Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > mysql callable statement problem

Reply
Thread Tools

mysql callable statement problem

 
 
lightning
Guest
Posts: n/a
 
      02-11-2007
my Mysql is 5.0.18

In database "test" I created a procedure:

mysql> delimiter //
mysql> create procedure demoSp(IN inputParam VARCHAR(255),INOUT
inOutParam INT)
-> begin
-> declare z INT;
-> set z=inOutParam + 1;
-> set inOutParam = z;
-> select inputParam;
-> select CONCAT('dfjd',inputParam);
-> end//

just add 1 to the IN/OUT param and select some stuff.
In fact this code is from the Mysql connector/J 's doc

In java code I wrote:

CallableStatement cStmt = con.prepareCall("{call demoSp(?,?)}");
cStmt.registerOutParameter(2, Types.INTEGER);
cStmt.setString("inputParam", "abc");
cStmt.setInt("inOutParam",2);

boolean had = cStmt.execute();
while (had) {
ResultSet rs = cStmt.getResultSet();
while (rs.next())
System.out.println(rs.getString(1));
had=cStmt.getMoreResults();
}
System.out.println(cStmt.getInt("inOutParam"));
con.close();

-----------------------------------
but the result is an error says "Out of range value adjusted for
column 'inOutParam' at row 1"
so I go on the net and search something says that I can solve this by
edit the my.ini, just remove the "STRICT_TRANS_TABLES" from the sql-
mode option and restart the db server.

I did this ,and the result give me:


abc
dfjdabc
1


no matter how I change the value of the "inOutParam", it just return
"1".

By accident , I just replace the line "

cStmt.setInt("inOutParam",2);

to

cStmt.setInt(1,2);

the result changes to be this:

2
dfjd2
3


My default charset is set to UTF-8

my connector/J version is 3.1.0
my jdk version 1.5.0

Is this a bug or did I miss something???

 
Reply With Quote
 
 
 
 
petersprc
Guest
Posts: n/a
 
      02-11-2007
Hi,

You can upgrade to the latest connector version which hopefully should
fix this.

There's a bug report here:
http://bugs.mysql.com/bug.php?id=15464

On Feb 11, 1:15 am, "lightning" <huang.lightn...@gmail.com> wrote:
> my Mysql is 5.0.18
>
> In database "test" I created a procedure:
>
> mysql> delimiter //
> mysql> create procedure demoSp(IN inputParam VARCHAR(255),INOUT
> inOutParam INT)
> -> begin
> -> declare z INT;
> -> set z=inOutParam + 1;
> -> set inOutParam = z;
> -> select inputParam;
> -> select CONCAT('dfjd',inputParam);
> -> end//
>
> just add 1 to the IN/OUT param and select some stuff.
> In fact this code is from the Mysql connector/J 's doc
>
> In java code I wrote:
>
> CallableStatement cStmt = con.prepareCall("{call demoSp(?,?)}");
> cStmt.registerOutParameter(2, Types.INTEGER);
> cStmt.setString("inputParam", "abc");
> cStmt.setInt("inOutParam",2);
>
> boolean had = cStmt.execute();
> while (had) {
> ResultSet rs = cStmt.getResultSet();
> while (rs.next())
> System.out.println(rs.getString(1));
> had=cStmt.getMoreResults();}
>
> System.out.println(cStmt.getInt("inOutParam"));
> con.close();
>
> -----------------------------------
> but the result is an error says "Out of range value adjusted for
> column 'inOutParam' at row 1"
> so I go on the net and search something says that I can solve this by
> edit the my.ini, just remove the "STRICT_TRANS_TABLES" from the sql-
> mode option and restart the db server.
>
> I did this ,and the result give me:
>
> abc
> dfjdabc
> 1
>
> no matter how I change the value of the "inOutParam", it just return
> "1".
>
> By accident , I just replace the line "
>
> cStmt.setInt("inOutParam",2);
>
> to
>
> cStmt.setInt(1,2);
>
> the result changes to be this:
>
> 2
> dfjd2
> 3
>
> My default charset is set to UTF-8
>
> my connector/J version is 3.1.0
> my jdk version 1.5.0
>
> Is this a bug or did I miss something???



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making Non Callable Objects Callable exiquio Python 2 10-07-2008 06:02 PM
Query in callable statement sanjeev.ssingh@gmail.com Java 2 10-10-2006 10:57 PM
Grabbing a object from the current code block using a callable statement? ChaosKCW Python 1 02-25-2006 09:20 PM
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM



Advertisments