Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/exam","root","password");
String q="insert into group"
+"(gname,des)"
+"values(?,?)";
PreparedStatement p=con.prepareStatement(q);
p.setString(1,gname);
p.setString(2,des);
p.executeUpdate();
con.close();
這是我添加組的代碼。但錯誤說我的查詢語法是錯誤的。我已經嘗試過使用表格中的單個核心,但仍然出現該錯誤。首先,我正在使用create語句,它也給出了相同的錯誤。請告訴我們這個查詢有什麼問題嗎?SQL查詢語法錯誤
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 'group(gname,des)values('Science','')' at line 1
sun.reflect.GeneratedConstructorAccessor16.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
com.mysql.jdbc.Util.getInstance(Util.java:408)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2490)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079)
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2013)
com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5104)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1998)
org.apache.jsp.groupreg_jsp._jspService(groupreg_j
表中是gname和des varchars? – yaswanth
是的,它們都是組表中的varchar。 – rango