带有JDBC的MySQL:
select * from mysql.proc
________________________
PreparedStatement selectClientIDsStatement = null;
Connection connection = Db.getConnection();
try {
String query = "select * from mysql.proc";
selectClientIDsStatement = connection.prepareCall(query);
...exception
} catch (SQLException e) {
throw new VeException(e);
} finally {...
}
=>功能*不存在
但是Workbench给出了正常的结果。为什么会这样呢?
最佳答案
似乎是一条奇怪的错误消息-我刚刚使用mysql-connector-java-5.1.34(针对5.5.42 MySQL Community Server)进行了尝试,并且它起作用了(没有异常,但是也没有返回行)...
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class MySQL {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root");
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery("select * from mysql.proc");
while (resultSet.next()) {
System.out.println("GOT A ROW!");
}
resultSet.close();
statement.close();
conn.close();
}
}
您的查询字符串是否包含硬空格或其他内容?
更新
看来您使用的是
prepareCall
而不是prepareStatement