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

[2591 byte] By [Peretz123a] at [2007-10-2 19:47:55]
# 1
I *think* it's barfing on your call string. Try this instead:String theMySQLCall = "{?=call sxma.sp_getnumber }";
dcmintera at 2007-7-13 22:26:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
No, that wasn't it. Any more ideas of what could be wrong? I'm using mySQL 5, J Connector 3.1.12, Java 1.4.2.Thanks.
Peretz123a at 2007-7-13 22:26:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Well, there's certainly something about that line that it doesn't like.

I'm not really familiar enough with MySQL to remote-debug this one for you, but it seems to be dying while trying to reconcile that call to its metadata for the sproc. Check the sproc declaration -does it return a single out value? Or does it have a single out value in the parameter list (not the same thing, I think) ? And so on.

Also, with the amended call that I provided is the failing stack trace identical, or slightly different? If different, could you post that too please?

Finally, do you have a known good sproc call that you can sanity check against? Perhaps take one of the examples from the MySQL site and check that that will work with their reference code?

dcmintera at 2007-7-13 22:26:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
My totally random guess is that MySQL doesn't correctly support stored procedures with no parameters; it looks as if it's barfing because it can't find a parameter list.Perhaps using a dummy input parameter would make it work.
StuDerbya at 2007-7-13 22:26:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
A strange fix worked. It's some sort of permissions issue. My DBA granted all permissions, but we don't know off the cuff what the problem is. Strange.
Peretz123a at 2007-7-13 22:26:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...