Click to See Complete Forum and Search --> : Using stored procedures in java


win006
07-07-2005, 01:37 AM
Hai

I need some help regarding calling stored procedures,I am using mysql server 2000 and i wrote a stored procedure

CREATE PROCEDURE fetchArtists @artist_id int
AS
begin
select * from Artists where artist_id=@artist_id
end
GO

and i am executing it from java using callable statement

CallableStatement stmt=con.prepareCall("{call fetchArtists(1)}");
ResultSet result=stmt.executeQuery();
while(result.next())
{
name1=result.getString(1);
homebase1=result.getString(2);
style1=result.getString(3);
art=result.getInt(4);
}

This is working fine

but i would like how to pass some dynamic input,instead of 1 i would like to input something dynamically into call fetchArtists(1)

I tried by taking i value and incrementing value using loop but i getting error of this sought

Errorjava.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification


Please help

Thank U

Oak
07-07-2005, 04:20 AM
For starters, MySQL and SQL Server 2000 are completely different databases.

Secondly, It would be good if you posted the loop that you used to try to add the data dynamically so that we have a better idea of the problem.

Cheers :)

win006
07-07-2005, 06:02 AM
Its sorted anyway and sorry, mysql server2000 there was typo in it i used
MS SQLSERVER 2000

Thanks anyway for ur reply

maverick9
06-01-2006, 09:30 AM
Hey win006,

You havent told how u have solved it...?

Any ways, here is how I solved the above exception.

#1. Use "?" instead of passing the value like "1" in call fetchArtists() as
CallableStatement stmt=con.prepareCall("{call fetchArtists(?)}");
#2.Set the value
stmt.setString(1,some_int_value);
Then rest is similar...
ResultSet result=stmt.executeQuery();
...
wishing fun with technology.
maverick.