PDA

View Full Version : error in query execution



iversonmania
Sep 11th, 2009, 05:31 AM
package project1;
package project1;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Types;


public class runquery {
public static void main (String[] args) throws InterruptedException
{
Connection conn =null;
CallableStatement cs = null;
ResultSet rs = null;
int updateQuery = 0;
try
{
String url = "jdbc:oracle:thin:@ahmad:1521:ORCL";
String user = "training";
String password = "training";
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("--------------");
conn = DriverManager.getConnection(url, user, password);
}
catch(Exception ex)
{
System.out.println("Error in creating the connection :"+ex.getMessage());
}
try
{
cs = conn.prepareCall("{call inout_fn4(?)}");
cs.registerOutParameter(1, Types.VARCHAR);

cs.execute();
String outParam = cs.getString(1);
System.out.println(outParam);



}
catch (Exception exp)
{

System.out.println("Error in Query execution ");
}
}}


SET serveroutput ON

DECLARE
retval VARCHAR2(20);
ioval VARCHAR2(20) := 'Going in';
BEGIN
retval := inout_fn4(ioval);
END;

running this in toad gives me correct answer

but with java it gives me this

Error in Query execution
Process exited with exit code 0.

iversonmania
Sep 11th, 2009, 05:47 AM
the inout_fn4 function is here

CREATE OR REPLACE FUNCTION inout_fn4 (outparm IN OUT VARCHAR2)
RETURN VARCHAR2 IS

BEGIN
outparm := 'Coming out';
RETURN outparm;
END inout_fn4;

Marten Deinum
Sep 11th, 2009, 06:40 AM
What has this question to do with spring?! Also print the stacktrace that probably contains the information needed (never swallow an exception!).

iversonmania
Sep 11th, 2009, 06:42 AM
I got the error, and solved it.

I am calling a function, which generates sql error.. the error is from that

i changed it into procedure, and am calling procedure which works..

and if i need to use a function... i am calling the procedure, and inside the procedure there is the function