Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

ORACLE Error !

  Asked By: Jesse    Date: Jun 03    Category: Java    Views: 773
  

In an effort converting an applet to servlet i am facing an issue with calling
procedures.
The servlet execution fails with an error :

java.sql.SQLException: ORA-01006: bind variable does not exist

Please let me know if anyone has come across such errors !

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Nagaraju Iyaner     Answered On: Jun 03

Below is a small example of a java  Program calling oracle  Stored Proc.
May be this can help you

import java.util.Properties;
import java.sql.Driver;
import java.sql.Connection;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.lang.Integer;
import oracle.jdbc.OracleTypes;

public class CallProc
{
public static void main(String[] args)
{
Properties props = new java.util.Properties();
props.put("user", "SCOTT");
props.put("password", "TIGER");
try
{
Driver d = (Driver)Class.forName
("oracle.jdbc.driver.OracleDriver").newInstance();

Connection conn = d.connect
("jdbc:oracle:thin:@localhost:1521:efg8ir3", props);

String sProc = "begin ? := MySquare(?); end;";

CallableStatement stmt = conn.prepareCall
(sProc);
// register the type of the out param - an
Oracle specific type
stmt.registerOutParameter(1,
OracleTypes.INTEGER);

// set the in param
stmt.setInt(2, 5);// Float(2, price);

// execute and retrieve the result set
stmt.execute();
//Integer im = (Integer)stmt.getObject(1);
//System.out.println(im.intValue());
System.out.println(stmt.getInt(1));

stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

The code for oracle stored proc is
CREATE OR REPLACE FUNCTION MySquare(i number)
RETURN number
AS
BEGIN
RETURN i * i;
END;

 
Didn't find what you were looking for? Find more on ORACLE Error ! Or get search suggestion and latest updates.




Tagged: