Error Calling a simple stored procedure
Hello. I'm using the code below to call a simple stored procedure which returns a number. Why does it throw the exception (Also below)?
Thank you,
Alek
=======================
Code:
import java.sql.*;
public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
//CallableStatement stmtMySQL = null;
long local_callkey = 0;
try
{
Class.forName("com.mysql.jdbc.Driver");
String userName = "abc";
String password = "def";
String url = "jdbc:mysql://mysqlserver/sxma";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
String theMySQLCall = "{?=call sxma.sp_getnumber()}";
CallableStatement stmtMySQL = conn.prepareCall(theMySQLCall);
stmtMySQL.registerOutParameter(1, Types.INTEGER);
stmtMySQL.execute();
int res = stmtMySQL.getInt(1);
if(res!=0)
throw new Exception("MySQL Query exception return code: " + String.valueOf(res) + ")");
else
{
local_callkey = stmtMySQL.getLong(1);
System.out.println("Local key is: " + local_callkey);
}
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server!");
e.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
================
Exception:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.charAt(String.java:444)
at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:951)
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1277)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3640)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:506)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:401)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4072)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4146)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4120)
at Connect.main(Connect.java:20)
Thank you for your help

