Acquiring Resultset from CallableStatement

Posted on 2004-09-18
Last Modified: 2006-11-17
Hi Experts...

I am trying to acquire a ResultSet from CallableStatement...

ResultSet rst;
CallableStatement cstmt;

String strSQL = "(call MY_PROC(?))";
String MyParam = "28900003";

cstmt = conn.prepareCall(strSQL, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
cstmt.setString(1, MyParam);
rst = (ResultSet) cstmt.getObject(1);

Here is my MS SQL Stored Procedure :

@MyParam varchar(20)
SELECT Field2,Field3 FROM Orders WHERE Field1=@MyParam

However I am getting this error on line cstmt.execute()...

java.sql.SQLException: [aveConnect][JDBC SQL Server Driver]  Line 1: Incorrect s
yntax near '28900003'.
        at net.avenir.jdbc2.k.q(
        at net.avenir.jdbc2.k.eb(
        at net.avenir.jdbc2.k.ib(
        at net.avenir.jdbc2.k.query(
        at net.avenir.jdbc2.a.b(
        at net.avenir.jdbc2.y.a(
        at net.avenir.jdbc2.y.execute(

Hope you could help me...   Thanks...   =)
Question by:aris_datuin
  • 2
LVL 86

Expert Comment

ID: 12091700
That looks to me like an incorrect syntax problem in the SP itself, and hence is not a Java problem yet

Accepted Solution

sbockelman earned 100 total points
ID: 12093003

You need to register an OUT paramter to hold the rs.

You need to use {} not () around your proc.

Read this article for details:

You may need to adjust some of the things for SQLServer vs. Oracle, but principles are similar.


Author Comment

ID: 12094650
Hi sbockelman...

This line solved my problem :

            You need to use {} not () around your proc.

Thanks..  =)

Expert Comment

ID: 12095763

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now