java - Using PreparedStament of JDBC with Mysql's TableName end with '\' -
i trying insert mysql database, has table name end '\
'. name 'abc\
'.
public static void main(string[] args) throws classnotfoundexception{ try { class.forname("com.mysql.jdbc.driver"); connection master = drivermanager.getconnection($url,$usr,$pwd); string st = "insert `abc\\` (`pad`,`c`,`k`,`id`) values(?,?,?,?)"; preparedstatement pstmt = master.preparestatement(st); pstmt.setint(1, 10); pstmt.setint(2, 1); pstmt.setstring(3, "1"); pstmt.setstring(4, "2"); pstmt.execute(); master.close(); }catch(sqlexception ex){ ex.printstacktrace(); }
but doesn't work, problem :
java.sql.sqlexception: parameter index out of range (1 > number of parameters, 0).
but, table's name 'a\bc
', backslash not last character, program works well.
can me solve problem? lot.
it working statement
.
public static void main(string[] args) throws classnotfoundexception, sqlexception { class.forname("com.mysql.jdbc.driver"); connection con = (connection) drivermanager.getconnection("jdbc:mysql://localhost:3306/test", "root", "password"); string st = "insert `abc\\` (`pad`,`c`,`k`,`d`) values(10,11,'5','6')"; statement stmt = (statement) con.createstatement(); stmt.execute(st); con.close(); }
Comments
Post a Comment