使用java将excel电子表格数据导入MYSQL数据库
使用以下命令更改您的查询:使用java将excel电子表格数据导入MYSQL数据库,java,jdbc,import-from-excel,Java,Jdbc,Import From Excel,使用以下命令更改您的查询: Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.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 '61.166666666666
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.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 '61.166666666666664`,`75.25`,'61.166666666666664',`61.166666666666664`,`75.25`)' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
at fibb.assessmentdatabase_3.main(assessmentdatabase_3.java:48)
String sql = "INSERT INTO description_process_level (process, level, a, b, c) VALUES('" + Process + "'," + Level + "," + A + "," + B + "," + C +")";
下面是一个如何使用预置语句的示例:
我尝试了这个方法,但现在它开始显示不同的错误,即线程“main”java.sql.SQLException中的-Exception:参数索引超出范围(1>参数数量,即0)。是的,当然数据库中有多少个参数,您应该指定要插入的参数,如字符串sql=”在描述中插入流程级别(p1、p2、p3、p4、p5)值(?、、?、?、?)“您可以看到my editString sql=“在描述中插入流程级别(流程、级别、a、b、c)值(流程、级别、a、b、c)”;pstm=(PreparedStatement)con.prepareStatement(sql);pstm.setString(1、流程);pstm.setDouble(2,级别);pstm.setDouble(3,A);pstm.setDouble(4,B);pstm.setDouble(5,C);仍然存在相同的错误。值中没有错误,只是生成值(?,,,,,,),这都是我编辑的答案。如果数据库中没有任何问题,这应该适用于您
String sql = "INSERT INTO description_process_level (process, level, a, b, c) VALUES('" + Process + "'," + Level + "," + A + "," + B + "," + C +")";
String sql = "INSERT INTO description_process_level (process, level, a, b, c) VALUES(?, ?, ?, ?, ?)";
pstm = (PreparedStatement) con.prepareStatement(sql);
pstm.setString(1, Process);
pstm.setDouble(2, Level);
pstm.setDouble(3, A);
pstm.setDouble(4, B);
pstm.setDouble(5, C);