Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. public class Test {
  2. public static void main(String args[]){
  3. try{
  4. Class.forName("com.mysql.jdbc.Driver");
  5. Connection con=(Connection) DriverManager.getConnection(
  6. "jdbc:mysql://localhost:3306/example??useUnicode=yes&characterEncoding=UTF-8","root","");
  7. String sql = "insert into test testname=?";
  8. PreparedStatement pstmt = (PreparedStatement) con.prepareStatement(sql);
  9. pstmt.setString(1, "~!@#$%^&*()_+|=-,.[}<>?{]".toString());
  10. pstmt.executeUpdate();
  11. con.close();
  12. }catch(Exception e){
  13. System.out.println(e);
  14. e.printStackTrace();
  15. }
  16. }
  17.  
  18. java.sql.SQLException: 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 'testname='~!@#$%^&*()_+|=-,.[}<>?{]'' at line 1
  19. at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
  20. at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
  21. at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
  22. at com.mysql.jdbc.Connection.execSQL(Connection.java:2376)
  23. at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
  24. at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860)
  25. at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1957)
  26. at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1880)
  27. at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1741)
  28. at me.cs.java.test.Test.main(Test.java:16)
  29. java.sql.SQLException: 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 'testname='~!@#$%^&*()_+|=-,.[}<>?{]'' at line 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement