Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void main(String args[]){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=(Connection) DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/example??useUnicode=yes&characterEncoding=UTF-8","root","");
- String sql = "insert into test testname=?";
- PreparedStatement pstmt = (PreparedStatement) con.prepareStatement(sql);
- pstmt.setString(1, "~!@#$%^&*()_+|=-,.[}<>?{]".toString());
- pstmt.executeUpdate();
- con.close();
- }catch(Exception e){
- System.out.println(e);
- e.printStackTrace();
- }
- }
- 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
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
- at com.mysql.jdbc.Connection.execSQL(Connection.java:2376)
- at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
- at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860)
- at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1957)
- at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1880)
- at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1741)
- at me.cs.java.test.Test.main(Test.java:16)
- 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