我试图连接到MySQL数据库Java和我收到以下错误:连接使用Java在Debian
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 '????????????????' at line 1
我无法理解的错误,并在网上搜索了很多,但没有发现任何东西。这是我正在使用的代码:
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception E)
{
System.err.println("Unable to load driver");
E.printStackTrace();
}
try
{
Connection C = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/DATABASE_NAME","USERNAME","PASSWORD");
Statement Stmt = C.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT somefield FROM sometable");
while (RS.next())
{
System.out.print("\"" + RS.getString(1) + "\"");
System.out.print(" by " + RS.getString(2));
System.out.println(": " + RS.getString(3));
}
C.close();
RS.close();
Stmt.close();
}
catch (SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
上面的SQL查询是问题的示例。我正在使用的那个在MySQL控制台中没有任何问题。事实上,即使我从上面的代码中删除查询和语句,我仍然会得到相同的错误。 有人可以帮忙吗? 在此先感谢
抛出异常行(在你的catch中添加一个E.printStackTrace())?另外,请尝试在查询结尾处添加分号,例如“从表格中选择字段;” – Taylor 2011-05-19 17:00:41
嗨,感谢您的评论,我也尝试添加分号,但在参考错误 – 2011-05-19 21:42:13