hi guys
I am having a frustrating problem with calling MYSQL database stored procedures.
the MySQL server being accessed is version 5.0.17, and the connector/J used is mysql-connector-java-5.0.3-bin.jar installed under the jre5.0/lib/ext/
when executing the SQL stateements in the java program, it all works fine. then when attempting to call procedure that does exactly the same thing as those SQL statement by using callablestaement = con.preparecall() method, it just failed on this connection preparing call statement.
I have checked lots of documentation info, but simply can't figure out what has possibly gone wrong. surely it doesnt look like a complicated task. it's so frustrating a thing to be stuck with such a simple task.
Could anyone give a helping hand here please? I have to use the stored procedure in my program. Any comment is much appreciated.
the little demo program is as follows:
import java.sql.*;
public class TestDB {
/**
// procedure being called is:
CREATE PROCEDURE `dbsaystorm`.`getsite` ()
BEGIN
select name from tblsite;
END
*/
public static void main(String[] args) {
try {
//Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbsaystorm",
"saystorm", "saystorm2006");
/**
* executing SQL statement here gives perfect correct results:
*/
// PreparedStatement ps = con.prepareStatement("select name from tblsite");
// ResultSet rs =ps.executeQuery();
// but stored procedure way...
CallableStatement proc = con.prepareCall("{call getsite}");
ResultSet rs =proc.executeQuery();
if (rs == null) return;
while (rs.next()){
System.out.println("site name is: "+ rs.getString(1));
}
rs.close();
} catch (SQLException e) {e.printStackTrace();}
catch (Exception e) {e.printStackTrace();}
}
}
and the result of run the demo program is as follows:
java.lang.NullPointerException
at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:959)
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1280)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3668)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:638)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:453)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4365)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4439)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4413)
at saystorm.server.data.database.TestDB.main(TestDB.java:16)