CallableStatement.getResultSet()
My Code:
cstmt = dbConn.prepareCall("{ call by_tick_nbr1(?, ?) }", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
cstmt.setInt(1, Integer.parseInt(ticketNum));
cstmt.registerOutParameter(2, Types.VARCHAR);
cstmt.execute();
System.out.println("Employ id = " + cstmt.getString(2));
resultSet = cstmt.getResultSet();
ResultSetMetaData rsmd = cstmt.getMetaData();
From the above Code:
CallableStatement.getResultSet() and CallableStatement.getMetaData are returns null. But CallableStatement.getString(2) returns the value from the database.
How to get ResultSet or ResultSetMetaData?
Kindly send me the solution immediately,
Thanks and Regards,
Bharat kumar R.
Put down the IDE and walk away from the code. Please go through the JDBC tutorial and when you have determined the problem then return.
Hint: Who said a stored procedure MUST return a result set?
Hint 2 : Nobody.
Hint 3 : And yours doesn't.
Similar Messages
-
i have some sql query to execute. so i save the query in a stored procedure. the stored procedure has no param. my query is like this:
create procedure [proc1]
as
select ... into #temp1 ...
select ... into #temp2 ...
select ... into #temp3 from #temp1 ... #temp2
update #temp3 ...
select * from #temp3
go
and my java code is like this:
// after get connection.
CallableStatement cs = con.prepareCall("proc1");
ResultSet rs = cs.executeQuery();
while (rs.next()) {
// ...but it throw SQLException with message "NO RESULT SET WAS PRODUCED."
my question is how to get resultset that hold #temp3 record?You should test your stored procedure first in a regular sql window first e.g. SQLServer Query Analyzer.
Your code should be ok if an empty resultset is returned so you need ensure that the stored procedure is doing what you expect.
You could consider using CallableStatement.execute() then CallableStatement.getResultSet() which returns null if there is no resultset (if not returning a resultset is expected behavior) -
Cannot read multiple resultsets from transaction datasource
I get a SQL exception "This object was closed() and cannot be used anymore."
when I try to access the first row of the second result set from a stored procedure.
This occurs when the code is running within an EJB using a transaction-capable
datasource hooked to a connection pool that uses the MSSQLSERVERv7 JDriver
to talk to SQL Server 7.0.
I noted that the resultset class used is weblogic.jdbc20.rmi.SerialResultSet.
The error occurs during the resultSet.next() call even though the resultset is
not null and getUpdateCount() returns -1.
However, the same code works correctly when run in a simple main() procedure from
the DOS command line, connecting directly to the database using only the classes
supplied with the JDriver product. The resultset class used in this case is
weblogic.jdbc.mssqlserver4.TdsResultSet.
The stored procedure is very simple, it just has two lines: SELECT 'Hello' and
SELECT 'World'. The Java code follows.
<PRE>
// ... code to get the connection ...
CallableStatement callableStatement = connection.prepareCall("{CALL spTest}");
callableStatement.execute();
ResultSet resultSet = callableStatement.getResultSet();
if ((resultSet != null) && resultSet.next())
System.out.println("Row from first result set:" + resultSet.getString(1));
callableStatement.getMoreResults();
resultSet = callableStatement.getResultSet();
if ((resultSet != null) && resultSet.next()) // this call to next() throws the
exception
System.out.println("Row from second result set:" + resultSet.getString(1));
resultSet.close();
callableStatement.close();
connection.close();
</PRE>
I am running WL5.10sp11 with mssqlserver4v70sp11 on NT4.0sp6a and JDK1.3.0_02
(HotSpot Client VM).
Regards,
Tom B.Tom Bechtold wrote:
>
Joe,
Here is the debug messages and trace with your diagnostic jar.
I hope this helps - Tom
we got Hello
java.sql.SQLException: java.lang.Exception: ResultSet originally closed at:
at weblogic.jdbcbase.mssqlserver4.TdsResultSet.close(TdsResultSet.java,
Compiled Code)
at java.lang.Exception.<init>(Unknown Source)
at weblogic.jdbcbase.mssqlserver4.TdsResultSet.close(TdsResultSet.java,
Compiled Code)
at weblogic.jdbcbase.jts.ResultSet.close(ResultSet.java:260)
at weblogic.jdbc20.rmi.internal.ResultSetImpl.close(ResultSetImpl.java:53)
at weblogic.jdbc20.rmi.SerialResultSet.close(SerialResultSet.java:54)
... rest of EJB call stack ...Hi. I do want to see the whole stack trace please, and also the EJB code.
thanks,
Joe
>
Joseph Weinstein <[email protected]> wrote:
Tom Bechtold wrote:
Hi Joe,
I pasted your sample program into my bean and ran it under
WL510sp11 and JDriver 5.1.0sp11, and it did exhibit the error
as my code did.
But it runs fine under WL510sp10 with JDriver 5.1.0sp11.
Thanks for your great support,
TomYou're very welcome. Please take the attached jar file, and add it
at the front of the server's weblogic.classpath, by editting the
startWebLogic script, and let me know what happens. This jar contains
the ResultSet class, with a hack to remember where it was closed, and
print that out if/when it is closed a second time.
Joe
Joseph Weinstein <[email protected]> wrote:
Tom Bechtold wrote:
A follow-on note: when I back out to Service Pack 10, the problem
is
not there,
so it seems that it is an issue with Service Pack 11.
- Tom Bechtold
"Tom Bechtold" <[email protected]> wrote:
I get a SQL exception "This object was closed() and cannot be used
anymore."
when I try to access the first row of the second result set from
a
stored
procedure.
This occurs when the code is running within an EJB using a transaction-capable
datasource hooked to a connection pool that uses the MSSQLSERVERv7JDriver
to talk to SQL Server 7.0.
I noted that the resultset class used is weblogic.jdbc20.rmi.SerialResultSet.
The error occurs during the resultSet.next() call even though theresultset
is not null and getUpdateCount() returns -1.Hi. You say that getUpdateCount() returns -1. I don't see that inthe
code you sent,
so you probably just gave us a representative sample of the code you
run. I did
runs uch code with the driver alone, and it works as you say. I will
see if I can
set up a server to do this via a DataSource, but in case anyone wants
to help/race with
me :-), here's simple code to run. If you convert it to a DataSource
connection,
and it behaves differently, I'll send you a diagnostic class to seewhat's
up...
Joe
Connection connection = null;
try
Properties properties = new Properties();
properties.put("user", "sa");
properties.put("password", "");
Driver d = (Driver)Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
connection = d.connect("jdbc:weblogic:mssqlserver4:JOE:1433",
properties);
// or get connection from DataSource...
Statement statement = connection.createStatement();
try {
statement.execute("drop procedure bla");
} catch (Exception e){}
statement.execute("create procedure bla as select 'Hello
' select 'world'");
CallableStatement c = connection.prepareCall("{ call bla()
c.execute();
ResultSet resultset = c.getResultSet();
while(resultset.next())
System.out.println("we got " + resultset.getString(1));
resultset.close();
c.getMoreResults();
resultset = c.getResultSet();
while(resultset.next())
System.out.println("we got " + resultset.getString(1));
resultset.close();
catch(SQLException exception1)
exception1.printStackTrace();
finally
try { connection.close();} catch(Exception ex) {}
However, the same code works correctly when run in a simple main()procedure
from the DOS command line, connecting directly to the database
using
only
the classes supplied with the JDriver product. The resultset classused in this
case
is weblogic.jdbc.mssqlserver4.TdsResultSet.
The stored procedure is very simple, it just has two lines: SELECT
'Hello'
and SELECT 'World'. The Java code follows.
// ... code to get the connection ...
CallableStatement callableStatement = connection.prepareCall("{CALLspTest}");
callableStatement.execute();
ResultSet resultSet = callableStatement.getResultSet();
if ((resultSet != null) && resultSet.next())
System.out.println("Row from first result set:" + resultSet.getString(1));
callableStatement.getMoreResults();
resultSet = callableStatement.getResultSet();
if ((resultSet != null) && resultSet.next()) // this call to next()throws the
exception
System.out.println("Row from second result set:" + resultSet.getString(1));
resultSet.close();
callableStatement.close();
connection.close();
I am running WL5.10sp11 with mssqlserver4v70sp11 on NT4.0sp6a and
JDK1.3.0_02
(HotSpot Client VM).
Regards,
Tom B.--
B.E.A. is now hiring! (12/14/01) If interested send a resume to [email protected]
DIRECTOR OF PRODUCT PLANS AND STRATEGY San Francisco,
CA
E-SALES BUSINESS DEVELOPMENT REPRESENTATIVE Dallas, TX
SOFTWARE ENGINEER (DBA) Liberty Corner,
NJ
SENIOR WEB DEVELOPER San Jose,CA
SOFTWARE ENGINEER (ALL LEVELS), CARY, NORTHCAROLINA
San Jose, CA
SR. PRODUCT MANAGER Bellevue,WA
SR. WEB DESIGNER San Jose,CA
Channel Marketing Manager - EMEA Region London, GBR
DIRECTOR OF MARKETING STRATEGY, APPLICATION SERVERS San Jose,CA
SENIOR SOFTWARE ENGINEER (PLATFORM) San Jose,CA
E-COMMERCE INTEGRATION ARCHITECT San Jose,CA
QUALITY ASSURANCE ENGINEER Redmond, WA
Services Development Manager (Business Development Manager - Services)
Paris, FRA; Munich, DEU
SENIOR SOFTWARE ENGINEER (PLATFORM) Redmond, WA
E-Marketing Programs Specialist EMEA London, GBR
BUSINESS DEVELOPMENT DIRECTOR - E COMMERCE INTEGRATION San Jose,CA
MANAGER, E-SALES Plano, TX--
B.E.A. is now hiring! (12/14/01) If interested send a resume to [email protected]
DIRECTOR OF PRODUCT PLANS AND STRATEGY San Francisco,
CA
E-SALES BUSINESS DEVELOPMENT REPRESENTATIVE Dallas, TX
SOFTWARE ENGINEER (DBA) Liberty Corner,
NJ
SENIOR WEB DEVELOPER San Jose, CA
SOFTWARE ENGINEER (ALL LEVELS), CARY, NORTH CAROLINA
San Jose, CA
SR. PRODUCT MANAGER Bellevue, WA
SR. WEB DESIGNER San Jose, CA
Channel Marketing Manager - EMEA Region London, GBR
DIRECTOR OF MARKETING STRATEGY, APPLICATION SERVERS San Jose, CA
SENIOR SOFTWARE ENGINEER (PLATFORM) San Jose, CA
E-COMMERCE INTEGRATION ARCHITECT San Jose, CA
QUALITY ASSURANCE ENGINEER Redmond, WA
Services Development Manager (Business Development Manager - Services)
Paris, FRA; Munich, DEU
SENIOR SOFTWARE ENGINEER (PLATFORM) Redmond, WA
E-Marketing Programs Specialist EMEA London, GBR
BUSINESS DEVELOPMENT DIRECTOR - E COMMERCE INTEGRATION San Jose, CA
MANAGER, E-SALES Plano, TX
B.E.A. is now hiring! (12/14/01) If interested send a resume to [email protected]
DIRECTOR OF PRODUCT PLANS AND STRATEGY San Francisco, CA
E-SALES BUSINESS DEVELOPMENT REPRESENTATIVE Dallas, TX
SOFTWARE ENGINEER (DBA) Liberty Corner, NJ
SENIOR WEB DEVELOPER San Jose, CA
SOFTWARE ENGINEER (ALL LEVELS), CARY, NORTH CAROLINA San Jose, CA
SR. PRODUCT MANAGER Bellevue, WA
SR. WEB DESIGNER San Jose, CA
Channel Marketing Manager - EMEA Region London, GBR
DIRECTOR OF MARKETING STRATEGY, APPLICATION SERVERS San Jose, CA
SENIOR SOFTWARE ENGINEER (PLATFORM) San Jose, CA
E-COMMERCE INTEGRATION ARCHITECT San Jose, CA
QUALITY ASSURANCE ENGINEER Redmond, WA
Services Development Manager (Business Development Manager - Services) Paris, FRA; Munich, DEU
SENIOR SOFTWARE ENGINEER (PLATFORM) Redmond, WA
E-Marketing Programs Specialist EMEA London, GBR
BUSINESS DEVELOPMENT DIRECTOR - E COMMERCE INTEGRATION San Jose, CA
MANAGER, E-SALES Plano, TX -
Error in accessing ResultSet - Descriptor index not valid SQL Exception
Hi
I am trying to execute a procedure in java and try to access the result set, but it is giving out Descriptor index not valid SQL Exception.
While printing the first record the error is thrown the code is as follows. Any help would be appreciated. Thanks in Advance.
1 . The Procedure
CREATE PROCEDURE library.fetchssncursor()
RESULT SETS 1
LANGUAGE SQL
BEGIN
DECLARE c1 CURSOR WITH RETURN FOR
SELECT * FROM VBPLTC.LTCP_DUMMY;
open c1;
END;2. Java Class
public class TestFunction2
public void getPassThruReport()
Connection objConnection=null;
ResultSet rs=null;
CallableStatement callableStatement=null;
try
List returnList=new ArrayList();
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
objConnection = DriverManager.getConnection("URL","USERID","PWD");
callableStatement = objConnection.prepareCall("{call fetchssncursor() }");
System.out.println("Got Connection "+ objConnection.toString());
callableStatement.execute();
rs = callableStatement.getResultSet();
// callableStatement.executeQuery (); i also tried this
if(rs!=null)
while(rs.next())
System.out.println(rs.getString(1)+","+rs.getString(2)+","+rs.getInt(3)+","+rs.getInt(4));
catch(SQLException e)
System.out.println("SQLException "+e);
catch(Exception e)
System.out.println("Exception "+e);
finally
try
if(rs!=null)
rs.close();
if(objConnection!=null)
objConnection.close();
catch (SQLException e) {
public static void main(String args[])
TestFunction2 obj = new TestFunction2();
obj.getPassThruReport();
}3. Output
Got Connection S101C3DE
shar,Sharath,123456,1 <------------- records
SQLException java.sql.SQLException: Descriptor index not valid.(1574
****************************************http://www-03.ibm.com/servers/eserver/iseries/toolbox/troubleshooting.htm
-
CallableStatament for selection stored procedure
hello,
i write a jsp page where there are inputs. when i click on a button i want to search elements in my sql server database. to do that, i call a stored procedure :
CREATE PROCEDURE PS_ELTS
@param0 VARCHAR(40),
@param1 VARCHAR(10),
@param2 VARCHAR(6),
@param3 VARCHAR(6),
@param4 VARCHAR(40)
AS
SELECT ELTS.NAME,
ELTS.TEL,
ELTS.ADR1,
ELTS.ADR2,
ELTS.SERV
FROM ELTS
WHERE (ELTS.NAME LIKE @param0 OR @param0 IS NULL)
AND (ELTS.TEL LIKE @param1 OR @param1 IS NULL)
AND (ELTS.ADR1 LIKE @param2 OR @param2 IS NULL)
AND (ELTS.ADR2 LIKE @param3 OR @param3 IS NULL)
AND (ELTS.SERV LIKE @param4 OR @param4 IS NULL)
ORDER BY ELTS.NAME, ELTS.TEL
i have a java class elts as business object. in the class, there is a method search which takes an elts event, connects to the database and gets elements which are ok. if all parameters are null, i get every lines of ELTS table. it's ok. if one or more of the parametre is not null, i don't get any line. this is the method :
public void search(UtilBean bean) throws Exception {
int i = 0;
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, login, password);
if (connection != null) {
connectionOk = true;
this.setNAME(beanrecherche.getNAME());
this.setTEL(beanrecherche.getTEL());
this.setADR1(beanrecherche.getADR1());
this.setADR2(beanrecherche.getADR2());
this.setSERV(beanrecherche.getSERV());
String aProc = "{call PS_ELTS(?,?,?,?,?)}";
CallableStatement aStatement = connection.prepareCall(aProc);
aStatement.setString(1, fmt_sqlChaineLike(this.getNAME()));
aStatement.setString(2, fmt_sqlChaineLike(this.getTEL()));
aStatement.setString(3, fmt_sqlChaineLike(this.getADR1()));
aStatement.setString(4, fmt_sqlChaineLike(this.getADR2()));
aStatement.setString(5, fmt_sqlChaineLike(this.getSERV()));
aStatement.execute();
ResultSet rs = aStatement.getResultSet();
while (rs.next()) {
i++;
UtilBean util = new UtilBean();
util.setNAME(rs.getString("NAME"));
util.setTEL(rs.getString("TEL"));
util.setADR1(rs.getString("ADR1"));
util.setADR2(rs.getString("ADR2"));
util.setSERV(rs.getString("SERV"));
listUtil.add(util);
do i do something wrong ? is there a solution to this problem ?i found what's wrong. in my stored procedure, i defined parameters like this :
@param0 VARCHAR(40),
@param1 VARCHAR(10),
@param2 VARCHAR(6),
@param3 VARCHAR(6),
@param4 VARCHAR(40)
when i use :
aStatement.setString(1, this.getNAME());
java sends a 40 characters long string to the stored procedure so if i write 'hello', the stored procedure gets 'hello '. any element is like that in the database so i must change the stored procedure :
(ELTS.NAME LIKE @param0 OR @param0 IS NULL) became (ELTS.NAME LIKE rtrim(ltrim(@param0)) OR @param0 IS NULL) -
Null pointer exceptions in CallableStatement
Hi,
Has anyone seen this problem before? I have an app that needs to invoke a stored proc on a SQLServer 2000 database, using the MS SQLServer 2000 JDBC drivers.
We were doing this via CallableStatement classes, but unless we specify implicit transactions in the stored proc itself, this fails with a null pointer exception at the point at which we try to retrieve the resultset from the CallableStatement, after calling CallableStatement.execute.
If I re-factor the code to use just plain Statement classes, and an SQL string that executes the stored proc (as if I were typing the SQL in query analyzer) then it works perfectly without needing to have implicit transactions turned on in the proc?
Any ideas?
Many thanks....Ok, broadly it's as follows:
CallableStatement stmt = conn.prepareCall("{Call MyStoredProc(?,?)}");
stmt.setString(1, null);
stmt.setString(2, "Test Value");
stmt.execute;
ResultSet rs = stmt.getResultSet();
if (rs.next()) {
System.out.println("RS1=" + rs.getString(1));
}That falls over at rs.next() unless the underlying stored proc has implicit transactions turned on. The stored proc can be executed through SQL Query Analyzer with the values used in my code successfully, also by just using 'normal' Statement classes and calling stmt.execute(sql) where sql is the string containg the sql I would use in query analyzer. -
Unable to execute an update statement using CallableStatement
Hi there,
I'm trying to run an update statement from JUnit using java.sql.CallableStatement and oracle.jbo.server.DBTransaction.
String updateSql =
"update footable set barcol=TO_DATE('12-SEP-09','dd-MM-yy') where bazcol = 505";
try {
statement =
applnModule.getDBTransaction().createCallableStatement(updateSql,
2);
int executeUpdate = statement.executeUpdate();
AppsLogger.write(this,
"# records UPDATED ------------------>" + executeUpdate,
AppsLogger.SEVERE);
} catch (SQLException s) {
s.printStackTrace();
Assert.fail("Encountered SQL Exception: " + s);
} finally {
try {
if (statement != null)
statement.close();
} catch (SQLException s) {
}Below is the exception I get when I run the above code. There is no problem with the SQL - it works fine from SQLDeveloper.
java.lang.AssertionError: Encountered SQL Exception: java.sql.SQLDataException: ORA-01858: a non-numeric character was found where a numeric was expected
org.junit.Assert.fail(Assert.java:91)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:105)
org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.invokeTestMethod(AtfJUnit4JTestCaseClassRunner.java:362)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.runMethods(AtfJUnit4JTestCaseClassRunner.java:272)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner$1.run(AtfJUnit4JTestCaseClassRunner.java:265)
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.run(AtfJUnit4JTestCaseClassRunner.java:262)Edited by: 911023 on Oct 2, 2012 11:28 AM
Edited by: 911023 on Oct 2, 2012 11:30 AMUsing case statement.
UPDATE gor_gold_post
SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END,
b49n = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END
WHERE tariff_code IN (169, 135, 136);Note: Code not tested. -
SQL Injection on CallableStatement
I will try to post this all in one line, as the tags are not working today. I know that one should use PreparedStatement over Statement to obviate the thread of a SQL injection attack. Is CallableStatement vulnerable as well? For reference, this would be running against an Oracle RDBMS. Thanks!
- SaishI guess there is no hard-and-fast rule.Well, I guess the hard and fast rule is "only use
bound variables". If you've got a sane database
design then that shouldn't cause you any problems.
Dave.I agree. I was approaching the issue mainly from a security perspective in locking down a legacy system against SQL injection attacks. Using Eclipse, I was able to zero-in on usages of Statement fairly easily. But the more I looked into CallableStatement, the more I realized that I woud have to inspect each invocation manually. (Just in case someone did not bind variables or built a dynamic SQL string).
- Saish -
Help needed in debugging callablestatement changing performance
Looking for some help debugging a performance problem.
We are in the process of converting an ASP web application running on IIS to a java web application running on OAS. We have java code using a CallableStatement that calls an Oracle PL/SQL Procedure that runs inserts and updates as needed and does not return anything.
When the Java application calls the procedure using the same parameters and doing the exact same work the execution time is either 3 minutes or 30 minutes. We have narrowed down the location of the slowdown and when it takes 30 minutes to execute it appears to be hanging during a cursor execution. What would cause the execution times to vary so much?
Here's another piece to the puzzle. When the procedure is called from IIS with the exact same parameters that were used from OAS the procedure ALWAYS runs in 3 minutes. Why would IIS performance be so consistent and OAS so inconsistent?
Any debugging suggestions would be greatly appreciated.
Thanks,
Bobuser4908334 wrote:
We are in the process of converting an ASP web application running on IIS to a java web application running on OAS. We have java code using a CallableStatement that calls an Oracle PL/SQL Procedure that runs inserts and updates as needed and does not return anything.
More information is needed on that.
There is one proc or 50?
The proc is being called one time or 50 times?
You are not using Batching right?
When the procedure is called from IIS with the exact same parameters that were used from OAS the procedure ALWAYS runs in 3 minutesYou are running the java server on exactly the same box as IIS?
The java code is using exactly the same database as IIS? (Did you verify this?) -
How to use CallableStatement for StroredProcedure in java?
I've successfully created storedProcedure for select comment in mysql.but how implement in java code with using of CallableStatement.Pls help me
Message was edited by:
SKVenkatestry this in main:
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
catch (Exception exc) {System.err.println("Eroare la incarcarea look & feel" + exc);} -
Getting error in cursor variable in CallableStatement
Hi,
I am trying to retrieve result set from PL/SQL procedure using cursor variable.
but I getting error sometime.
this is code in my program...
CallableStatement pstmt=null;
pstmt = con.prepareCall("{call Crms2.SearchRNameTime(?,?,?,?,?,?)}");
pstmt.setString(1, uid);
pstmt.setString(2, strBookingDate);
pstmt.setInt(3, roomid);
pstmt.setInt(4, lngStartTime);
pstmt.setInt(5, lngEndTime);
pstmt.registerOutParameter(6, oracle.jdbc.driver.OracleTypes.CURSOR ); // error accured in this line
pstmt.execute();
rs = (ResultSet)pstmt.getObject(6);
error was accrued at line : pstmt.registerOutParameter(6, oracle.jdbc.driver.OracleTypes.CURSOR );
error is: orable.jdbc.driver can not resolve tha symbol..
but it some time executing , some time giving error.
it is require any package to import?
please help me on this problem.
regards
Narru990187 wrote:
i have created a cursor to return only 5th row from a table .
declare
cursor cur is select * From(select last_name,salary,rownum rn from employees where rownum<=50)) where rn=5;
just a side note, (others have helped with the actual error already), using "rownum" like you do isn't very consistent. Not really sure about the requirment of "5th row", but no matter. Just keep in mind that the way Oracle assigns a rownum, and the fact you have no sorting/order ... you are - effectively - getting a random row. That is, with no data changing, Oracle may very well retrieve things in a different order due to index, new oracle version, whatever.
If you do actually need the 5th row where you have some sorting (ie 5th largest salary, or 5th record by last name, etc. ), then you may want to consider something like:
select * from (select last_name, salary, row_number() over (order by salary desc) rn from employees) where rn = 5;
or whatever your sort criteria is. Do a search for "Top N" queries if you need more info.
It'll work a bit more consistently. -
JRC with JavaBeans datasrc - how to pass params into javabean.getResultSet?
Hi.
I'm developing javabeans data sources for crystal reports for the java/JRC engine. I've seen the document entitled Javabeans Connectivity for Crystal. It TALKS ABOUT passing params into the methods that return java.sql.ResultSets but there is absolutely no example code anywhere that I can find on how to do it.
What I don't understand is: Since the JRC engine is basically controlling the instantiation of the javabean, other than calling some type of fetch method in the constructor, how the heck am I supposed to pass in db connection info and a sql string?
Anybody got sample code for how to call/where to call parameters that I would put in a custom getResultSet method??
Thanks.I don't think that a Connection Pool class would be an ideal candidate for becoming a JavaBean. One of the most prevalent use of a JavaBean class it to use it as a data object to collect data from your presentation layer (viz. HTML form) and transfer it to your business layer. If the request parameter names match the Bean's property names, a bean can automatically get these values and initialize itself even though it has a zero argument ctor. Then a Bean could call methods in the business layer to do some processing, to persist itself etc.
-
Does callableStatement.SetNull() work fine with ojdbc5.jar in oracle 11gr2
Hello,
CallableStatement.setNull(1, Types.ARRAY) throws java.sql.SQLException: Invalid column type: sqlType=2003
and
CallableStatement.setNull(1, Types.ARRAY, "SOMEARRAYTYPE") throws java.sql.SQLException: ORA-06531: Reference to uninitialized collection
ORA-06512: at "SYSTEM.SOMEARRAYTYPE", line 6
ORA-06512: at line 1
Is this a problem with the driver? Is there any other way of setting null value for a parameter of ARRAY type?
Thanks.user8915609 wrote:
But setNull(..) itself means that we are setting a null value. doesn't it?I dunno.. what does the Java docs say?
I am using setNull(..) instead of setObject(..) because i want to set a null value for an array parameter of the stored procedure.Well, that does not seem to be working, does it? So it is reasonable to assume that your are not correctly using/understanding what the setNull() call does.
For example (following on from the sample code I posted above), it depends on what one attempts to set to null in a collection:
SQL> declare
2 variable TStrings;
3 begin
4 --// a variable can be null
5 variable := null;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL>
SQL> declare
2 variable TStrings;
3 begin
4 --// a collection item cannot be null if the
5 --// collection itself has not been instantiated
6 variable(1) := null;
7 end;
8 /
declare
ERROR at line 1:
ORA-06531: Reference to uninitialized collection
ORA-06512: at line 6
SQL>
SQL> declare
2 variable TStrings;
3 begin
4 --// instantiate with 2 items/strings in the collection
5 variable := new TStrings('1','2');
6
7 --// now we can set an existing item to null
8 variable(1) := null;
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> If you code a command in ANY language, then you need to know EXACTLY what the command does, and why you are using it.
If not - then it is a fail on your part. -
JDBC - CallableStatement - Error in Accessing Stored Procedure of MS SQL
Dear Friends,
The following is the code to access a stored procedure of MS SQL Server 7.0 sp4,
try
CallableStatement cstmt;
ResultSet rst;
cstmt = connection.prepareCall("{call backupdb[?,?]}");
cstmt.setString("db_name","SBIREMITLIVE");
cstmt.setString("path", "c:\testing.bak");
cstmt.executeQuery();
System.out.println("Stored Procedure called successfully");
catch(SQLException se)
System.out.println(se.toString());
when i execute this i am getting the error as " MS ODBC-MS SQL Server Syntax error or Access Violation "
What's the problem exactly ? anybody came across this issue..if so...kindly help me....
Here is my MS SQL Server stored procedure.....for reference
create procedure backupdb(@db_name varchar(40), @path varchar(100)) as
Backup database @db_name to disk = @path
Regards,
V.PrasannaDear DigitalDreamer,
Yes, as per your suggestion, it's working fine...thanks a lot...
here is the code...
CallableStatement cstmt;
ResultSet rst;
cstmt = connection.prepareCall(" exec backupdb ?,? ");
cstmt.setString(1,"SBIREMITLIVE");
cstmt.setString(2, "c:\\testing.bak");
cstmt.execute();
Regards,
V.Prasanna -
Hi Guys
I am having some problem as I am using a DataSource for connections and randomly
the CallableStatements and PreparedStatements created from this DataSource becomes
null and everytime I get NullPointerException with this message.
java.sql.SQLException: java.lang.NullPointerException
at weblogic.jdbc.rmi.SerialPreparedStatement.setString(SerialPreparedStatement.java:210)
at .........
Help will be appreciated..Hi Guys
I am having some problem as I am using a DataSource for connections and randomly
the CallableStatements and PreparedStatements created from this DataSource becomes
null and everytime I get NullPointerException with this message.
java.sql.SQLException: java.lang.NullPointerException
at weblogic.jdbc.rmi.SerialPreparedStatement.setString(SerialPreparedStatement.java:210)
at .........
Help will be appreciated..
Maybe you are looking for
-
Is there any way of importing stuffs from Microsoft Access to SQL Server?
I have quite a big store of information Microsoft Access DB, but now i am required to switch to SQL Server? Is there any way of importing to SQL Server, either by Java programming or manually? Thank you in advance.
-
Diff between XSL - JAVA and XSL - ABAP
Hi All, What is the difference between the XSLT in JAVA and XSL in ABAP? which is the preferable one.
-
Error when converting time stamp in date time time zone CST in IC
Hi Experts, We have recently upgraded from CRM 5.0 to CRM 2007. We are using IC WEB Employee interaction center. so when agent create service ticket in interaction center and close the ticket on same day we are getting an error saying Error when conv
-
Controlling a MacBook Pro from a MacBook Air
Hi Can I control a MB Pro from a MB Air whilst the lid of the Pro is shut? Thanks Philip
-
Configuring Input Agent directory on a machine different from the UCM one
I have configured InputAgent (Oracle Imaging and Process Management) to pick work from /IPM/Input/<XYZ dir> on ABC MACHINE (where UCM and weblogic is installed) and in my input definition i have an input mask (abc.txt) configured to read files from /