• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call a stored procedure from java

 
Radha MahaLakshmi
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am using sybase database and trying to call a SP.
The following code i am using.
import java.sql.*;
public class javaTest
{
public static void main(String [] str1)
{
try
{
String svr = "tkd-imsyb-01.tk.jp.chase.com:4100";
String uid ="JBOND";
String pwd ="waltherppk";
String department = "MTB";
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
Connection con = DriverManager.getConnection("jdbc:sybase:Tds:"+svr,uid, pwd);
Statement stm = con.createStatement();
ResultSet rst = stm.executeQuery("exec get_user_func 'YKIDACHI','cftrade' ");
while(rst.next())
{
System.out.println("-----:"+rst.getString(0));
}

}catch(Exception e)
{
e.printStackTrace();
}
}
}

When i run this program its giving the following exception.
java.sql.SQLException: JZ0R2: No result set for this query.
at com.sybase.jdbc2.jdbc.ErrorMessage.raiseError(ErrorMessage.java:482)
at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybStatement.java:1525)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:149
5)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:402
)
at javaTest.main(javaTest.java:22)

If i execute the SP from isql it gives me a result.
Can some body help me.
Radha
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use java.sql.CallableStatement for executing stored procedures.
 
Radha MahaLakshmi
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I need to soecidy the db name before SP name as matrix_xref..get_user_func insted get_user_func then its working.
Thanks
Radha
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic