Py学习  »  DATABASE

JDBC CallableStatement:java.sql.SQLException:指定为定义者的用户('mysql.infoschema'@'localhost')不存在

陈培鸿 • 4 年前 • 264 次点击  

    Connection connection=null;
    CallableStatement statement=null;

    try {
        connection = DriverManager.getConnection(DBTools.getDbUrl(), DBTools.getUSER(),DBTools.getPASSWD());
        String getNameSQL="{call getName (?,?)}";
        statement=connection.prepareCall(getNameSQL);
        int empID=103;
        String empName;
        statement.setInt(1,empID);
        statement.registerOutParameter(2, Types.VARCHAR);
        System.out.println("Execute: "+statement.execute());
        empName=statement.getString(2);
        System.out.println("Emp Name with ID:" + empID + " is " + empName);
        statement.close();
        connection.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }

其控制台输出为:

java.sql.SQLException: The user specified as a definer ('mysql.infoschema'@'localhost') does not exist
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:970)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1020)
at com.mysql.cj.jdbc.DatabaseMetaDataUsingInfoSchema.executeMetadataQuery(DatabaseMetaDataUsingInfoSchema.java:70)
at com.mysql.cj.jdbc.DatabaseMetaDataUsingInfoSchema.getProcedureColumns(DatabaseMetaDataUsingInfoSchema.java:769)
at com.mysql.cj.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:790)
at com.mysql.cj.jdbc.CallableStatement.<init>(CallableStatement.java:585)
at com.mysql.cj.jdbc.CallableStatement.getInstance(CallableStatement.java:484)
at com.mysql.cj.jdbc.ConnectionImpl.parseCallableStatement(ConnectionImpl.java:1523)
at com.mysql.cj.jdbc.ConnectionImpl.prepareCall(ConnectionImpl.java:1548)
at com.mysql.cj.jdbc.ConnectionImpl.prepareCall(ConnectionImpl.java:1539)
at main.JDBCCallableStatement.main(JDBCCallableStatement.java:13)

我确信mysql函数getName()已经创建并且运行良好,看起来问题在于连接,但是我不知道如何修复它,希望您能给我一些建议。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55437
 
264 次点击