请大家帮忙看一下,是什么原因代码如下:
// SQL文
String sql = ""; // 导入Access
sql = "insert into tbTest select * from openrowset(’Microsoft.Jet.OLEDB.4.0’,’C:\test\Test.mdb';'';'’,tbTest)"; try {
// 创建连接对象
conn = ConnectionFactory.getConnection(connMySQL); conn.setAutoCommit(false); // 创建PreparedStatement对象
preparedStatement = conn.prepareStatement(sql); // 执行SQL文
preparedStatement.executeUpdate(); conn.commit(); } catch (Exception e) {
e.printStackTrace();
}错误内容:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(???Microsoft.Jet.OLEDB.4.0???,???C:\test\Test.mdb';'';'???,tbTest)' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1027)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3378)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3310)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1853)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1976)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2022)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
at WanFang.dao.impl.DaoImpl.moveData(DaoImpl.java:60)
at WanFang.GUI.DataMoveFrame.actionPerformed(DataMoveFrame.java:366)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
// SQL文
String sql = ""; // 导入Access
sql = "insert into tbTest select * from openrowset(’Microsoft.Jet.OLEDB.4.0’,’C:\test\Test.mdb';'';'’,tbTest)"; try {
// 创建连接对象
conn = ConnectionFactory.getConnection(connMySQL); conn.setAutoCommit(false); // 创建PreparedStatement对象
preparedStatement = conn.prepareStatement(sql); // 执行SQL文
preparedStatement.executeUpdate(); conn.commit(); } catch (Exception e) {
e.printStackTrace();
}错误内容:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(???Microsoft.Jet.OLEDB.4.0???,???C:\test\Test.mdb';'';'???,tbTest)' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1027)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3378)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3310)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1853)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1976)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2022)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
at WanFang.dao.impl.DaoImpl.moveData(DaoImpl.java:60)
at WanFang.GUI.DataMoveFrame.actionPerformed(DataMoveFrame.java:366)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
这里应该有一个 values,
insert into tbTest values(),
没有这么用过,我的习惯是用一个方法取值,封装到list里面,另一个方法insert,有错误也好查找。
MYSQL没有OPENROWSET、OPENDATASOURCE
不是这个问题
[align=center]==== 思想重于技巧 ====
[/align]
.
贴子分数<20:对自已的问题不予重视。
贴子大量未结:对别人的回答不予尊重。
.
public static string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\test\\Test.mdb;Persist Security Info=False"; public OleDbConnection accessConn = new OleDbConnection(strAccessConn); String sql = "";
sql = "SELECT * INTO tbtest IN ODBC[ODBC;Driver={MySQL ODBC 5.1 Driver};Server=localhost;Port=3306;Database=wanfangvideo;USER=root;Pwd=sa;] FROM tbTest;"; OleDbCommand cmd = new OleDbCommand(sql, accessConn); OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmd);
accessConn.Close();执行时,没有报错,到数据也没有导到MySQL中.
SQL文我在Access中执行过,是对不知道是什么原因
那位大侠帮忙,看一下