我得到异常下面如何查询在Java JDBC字符串
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 '?http://www.andhrabhoomi.net/' at line 1
我想查一下我的数据库中是否存在串
我的代码:
sql = "SELECT url FROM data where url = ?"+ "string";
ResultSet rs = statement.executeQuery(sql);
System.out.println(rs);
上导致'sql'变得'选择URL FROM数据,其中URL = string',这是无效的(“?string”不是SQL语法的一部分,也不是文字) –
您是使用Statement还是PreparedStatement?请通过: http://www.tutorialspoint.com/javaexamples/jdbc_prepared_statement.htm – Suyash
也如果你这样做是坏的方式上面,字符串需要引用。 –