This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to call a stored procedure from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to call a stored procedure from java" Watch "How to call a stored procedure from java" New topic
Author

How to call a stored procedure from java

Radha MahaLakshmi
Ranch Hand

Joined: Mar 28, 2003
Posts: 45
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
Use java.sql.CallableStatement for executing stored procedures.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Radha MahaLakshmi
Ranch Hand

Joined: Mar 28, 2003
Posts: 45
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
 
subject: How to call a stored procedure from java