带JDBC的MySQL:select * from mysql.proc =>功能*不存在

时间:2015-04-20 14:49:32

标签: java mysql jdbc

使用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给出了正常的结果。为什么会这样?

1 个答案:

答案 0 :(得分:1)

看起来像一个奇怪的错误消息 - 我只是尝试使用mysql-connector-java-5.1.34(针对5.5.42 MySQL社区服务器)并且它工作(没有异常,但也没有返回行)... < / p>

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