?
Solved

Acquiring Resultset from CallableStatement

Posted on 2004-09-18
4
Medium Priority
?
1,442 Views
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);
cstmt.execute();
rst = (ResultSet) cstmt.getObject(1);


Here is my MS SQL Stored Procedure :

PROCEDURE MY_PROC
@MyParam varchar(20)
AS
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(Protocol.java)
        at net.avenir.jdbc2.k.eb(Protocol.java)
        at net.avenir.jdbc2.k.ib(Protocol.java)
        at net.avenir.jdbc2.k.query(Protocol.java)
        at net.avenir.jdbc2.a.b(Statement.java)
        at net.avenir.jdbc2.y.a(CallableStatement.java)
        at net.avenir.jdbc2.y.execute(CallableStatement.java)

Hope you could help me...   Thanks...   =)
0
Comment
Question by:aris_datuin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Expert Comment

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

Accepted Solution

by:
sbockelman earned 400 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:

 http://www.enterprisedt.com/publications/oracle/result_set.html

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

http://www.mcse.ms/archive90-2004-4-594262.html

0
 

Author Comment

by:aris_datuin
ID: 12094650
Hi sbockelman...


This line solved my problem :

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


Thanks..  =)
0
 
LVL 3

Expert Comment

by:sbockelman
ID: 12095763
cool!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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