CallableStatement vs PreparedStatement.

I've been working with callable statements for a project with a SQL server 2000 database.
I had to change all those callable statements to prepared statement.
The time to excute the project is way less with the prepared statement (22s vs 50s).
The database is small but with a lot of tables (80), and i had the same amount of stored procedures.
My JDBC driver is from Microsoft (a beta version of the Merant one).
Does anyone know why the prepared statements are faster ??
Thanks.
C�dric.

The SQL used to implement the prepared statement is optimized once at prepare time and then executed on call with the parameters passed. For any statement executed a number of times this will be faster than constantly repreparing the statement on every execution. The prepared statements do consume resources on the database server and so they should not be 'held' longer than they are needed.

Similar Messages

  • Java.lang.NullPointerException when using DataSource connection and executing CallableStatement

    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..

  • JDBC and creation of external tables with positions

    Hello,
    this might be a trick question or I am probably running around in circles with this one. I know that it is not possible to call pl/sql command ("set define off") using a jdbc connection. Correct me on this one if I am wrong ;)
    So the point why I want to that is because I want to execute the following stmt using a CallableStatement:
    prompt
    prompt: CREATE TABLE "TEST_IN"."TEST_RECEIPT_EXTERNAL" ...
    prompt
    CREATE TABLE "TEST"."TEST_RECEIPT_EXTERNAL"
    ("APPLE" VARCHAR2(8 CHAR)
    ,"PIE" VARCHAR2(1 CHAR)
    ,"RECEIPT" VARCHAR2(58 CHAR)
    ORGANIZATION EXTERNAL
    (TYPE ORACLE_LOADER
    DEFAULT DIRECTORY "TEST_IN"
    ACCESS PARAMETERS
    (records delimited by newline
    fields (
    APPLE position(1: 8) CHAR(8),
    PIE position(9: 9) CHAR(1),
    RECEIPT position(10: 67) CHAR(58), )
    LOCATION
    ("TEST_IN":'FLIP.FLOP.19760104170600'))
    REJECT LIMIT UNLIMITED
    PARALLEL 1
    which gives me back the expected error:
    Missing IN or OUT parameter at index:: 1
    Any thoughts on this one would be very helpful - thanks in advance,
    Sascha

    Perfect - did not thought that the behavior of Statement, CallableStatement and PreparedStatement is different. In retrospect and thinking about the use cases of the implementations I probably should have thought about that my self.
    Thanks a lot - problem solved :)

  • Batch statement with sql server 2000 driver

    Hi,
    I have been using the jdbc bridge and recently upgraded to the sql server 2000 driver. I have some code that was working correctly executing some batch commands. But with the new driver it no longer works. Its throwing errors. Can anyone help? I have tried removing the begin/end statments and that causes a different error to be thrown.
    Statement s = db.createStatement();
    s.addBatch("Begin");
    s.addBatch("use master");
    s.addBatch("EXEC sp_addlogin '" + login +"','" + loginAuth + "','testDB'");
    s.addBatch("use testDB");
    s.addBatch("EXEC sp_grantdbaccess '" + login + "' , '" + login + "'");
    s.addBatch("End");
    s.executeBatch();

    I have been using the jdbc bridge and recently
    upgraded to the sql server 2000 driver. i think you maybe are sol...
    Statement s = db.createStatement();
    s.addBatch("Begin");
    s.addBatch("use master");
    s.addBatch("EXEC sp_addlogin '" +
    p_addlogin '" + login +"','" + loginAuth +
    "','testDB'");
    s.addBatch("use testDB");
    s.addBatch("EXEC sp_grantdbaccess '" +
    ntdbaccess '" + login + "' , '" + login + "'");
    s.addBatch("End");
    s.executeBatch();the documentation from microsoft reads...
    for both CallableStatement and PreparedStatement
    void addBatch (String)
    Not Supported
    Throws "invalid method call" exception.
    is this the error you are seeing?

  • Batch updates with callable/prepared statement?

    The document http://edocs.bea.com/wls/docs70/oracle/advanced.html#1158797 states
    that "Using Batch updates with the callableStatement or preparedStatement is
    not supported". What does that actually mean? We have used both callable and prepared
    statements with the batch update in our current project (with the Oracle 817 db).
    It seems to run ok anyway.

    So the documentation should state that batch updates do not work ok in old versions
    of JDriver for Oracle, BUT work correctly with newer version. Additionally, batch
    updates work ok when used with Oracle supplied jdbc-drivers?
    "Stephen Felts" <[email protected]> wrote:
    Support for addBatch and executeBatch in the WLS Jdriver for Oracle was
    added in 7.0SP2.
    It was not available in 6.X or 7.0 or 7.0SP1.
    "Janne" <[email protected]> wrote in message news:3edb0cdc$[email protected]..
    The document http://edocs.bea.com/wls/docs70/oracle/advanced.html#1158797
    states
    that "Using Batch updates with the callableStatement or preparedStatementis
    not supported". What does that actually mean? We have used both callableand prepared
    statements with the batch update in our current project (with the Oracle817 db).
    It seems to run ok anyway.

  • JSP hanging when 9i database invoked through JSP

    Hi
    I have just installed Oracle 9i DB on Win 2000 server. When I try to invoke a SQL from a jsp on the application server on the same machine, it hangs.
    The jsp is able to connect to the Oracle 8i database on a different machine. We are having classes13.zip in the classpath.
    Has somebody faced this problem before? Pl. help me out
    Its urgent.
    Thanks in advance
    Ashish.

    hi Vipul
    Following is the file that we are using to connect to the database. The following file is invoked from the command prompt and it takes very long (8 minutes on the same machine) to connect to Oracle 9i. With JSP (tested on JRun and Oracle9iAS), we are never able to connect. The JSP and java file from command prompt both give instantaneous results even from a remote database if the DB is Oracle 8i.
    Thanks
    import java.io.*;
    import java.sql.*;
    public class DBInserter {
    Connection connection = null;
    CallableStatement callableStatement = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    java.sql.Date date1 = new java.sql.Date(System.currentTimeMillis());
    public DBInserter(String custCode , String itemCode , String uomCode , String itemQty , String itemRate , String discPerc , String docNo) {
    getDBConnection();
    // insertValues(custCode , itemCode , uomCode , itemQty , itemRate , discPerc , docNo);
    getValues();
    public DBInserter() {
    getDBConnection();
    getValues();
    public void getDBConnection() {
    try {
    Class.forName("oracle.jdbc.OracleDriver");
    System.out.println("Abt to get the connection " + System.currentTimeMillis());
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    connection = DriverManager.getConnection("jdbc:oracle:thin:@129.1.2.116:1521:ORCL","SCOTT","TIGER");
    System.out.println("After getting the connection " + System.currentTimeMillis());
    catch(Exception ex) {
    System.out.println("Connection refused : " + ex.getMessage());
    public void getValues() {
    try {
    preparedStatement = connection.prepareStatement("SELECT * FROM DEPT");
    resultSet = preparedStatement.executeQuery();
    while(resultSet.next()) {
    System.out.println(resultSet.getString("DEPTNO"));
    catch(Exception ex) {
    public void insertValues(String custCode , String itemCode , String uomCode , String itemQty , String itemRate , String discPerc , String docNo) {
    try {
    callableStatement = connection.prepareCall("{ CALL SO_INSERT_XML(?,?,?,?,?,?,?,?,?,?) }");
    callableStatement.setString(1,custCode);
    callableStatement.setString(2,itemCode); // ItemCode
    callableStatement.setString(3,uomCode); // ItemUomCode
    callableStatement.setInt(4,Integer.parseInt(itemQty)); // Item Qty
    callableStatement.setInt(5,Integer.parseInt("0")); // Item Ls Qty
    callableStatement.setInt(6,Integer.parseInt(itemRate)); // Item Rate
    callableStatement.setInt(7,Integer.parseInt(discPerc)); // Item Disc Perc
    callableStatement.setDate(8,date1);
    callableStatement.setInt(9,Integer.parseInt(docNo));
    callableStatement.registerOutParameter(10,Types.INTEGER);
    System.out.println("Abt to insert the values");
    callableStatement.executeUpdate();
    System.out.println("After inserting the values");
    System.out.println("The Value inserted is : " + callableStatement.getInt(10));
    catch(Exception ex) {
    System.out.println("Exception while inserting the values : " + ex.getMessage());
    public static void main(String args[]) {
    //DBInserter dbi = new DBInserter(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
    DBInserter dbi = new DBInserter();
    null

  • Oracle insert

    I have oracle 9i over jdbc and table process, where
    are columns process_id (Numeric) and process_name (varchar2).
    Column process_id every time incremented.
    How I can insert and back process_id with one sql statement?
    Here I do:
    insert into process (name) values ('Name');
    select process_id from prosesss order by process_id desc; (first row)
    but I wanna do:
    insert into process (name) values ('Name') returning process_id;
    This is not work...
    Any help please!

    Yes it does work with CallableStatement.
    CallableStatement extends PreparedStatement and adds the methods
    T getT(int index);
    to retrieve OUT parameters, one for each setT method.
    Then it adds registerOutParameter(int index, int sqlType)
    Here is an example SQL query that I use with Oracle 9.2 and JDBC:
    BEGIN
    INSERT INTO SPEXTRACT_RATING (
    RATING_ID,
    MULTIMEDIA_CONTENT_ID,
    APPLICATION_USER_ID,
    RATING_CODE,
    RATING_TEXT,
    END_TIME
    ) VALUES (SPEXTRACT_RATING_SEQUENCE.NEXTVAL, ?,?,?,?, SYSDATE)
    RETURNING RATING_ID INTO ?;
    END;
    I set the parameters 1 through 4 and
    registerOutParameter(5, Types.INTEGER)
    that step is required. Then I execute() that CallableStatement and I
    can retrieve the assigned RATING_ID with getLong(5) just fine.
    It works and I'm glad it does.
    PS: of course one wonders why this must be so difficult, but that's this SQL madness...

  • Newbie question - getMax?

    Hi, I'm a totally green, absolute beginner etc etc JDBC developer.
    I have two java programs - the first queries a table with a straightforward select statement, and the second one gets the Max value of a field from a table. Both work wonderfully.
    Question is, I need to use the Max value in the first program. I've come across several resources that suggest different ways of doing this but I'm unable to find a good example from which to crib.
    The methods I believe I can adopt would be to run a CallableStatement, a PreparedStatement, and I've also found a method getMax. Which would be the best/correct one to use?
    I realise that this might seem like a very basic question, but I've been drafted into a project from mainframe world!
    Thanks in advance.

    Huh?
    Figure out what the select statement you would issue
    to get the information directly from the database.
    Create a prepared statement for this query.
    Execute the prepared statement, retrieve the result
    set for the query, and extract the columns you are
    interested in from the result set.
    Without knowing what problems you're encountering I
    can't be more specific than that.Yup, I kind of thought that I hadn't formulated the question properly :)
    No matter, I think I have the solution. When I find out how to formulate the question, perhaps I'll post that here!
    Thanks for looking!

  • Database Procedure Calling by Using PreparedStatement and CallableStatement

    Hi
    We can execute Database Stored Procedure by using PreparedStatement and CallableStatement as well.Then what is the significance of having CallableStatement.
    Please let me know the difference between these two Statement objects particularly in Stored Procedures Execution.
    Thanks in advance
    Basha007

    A callable statement excecutes a stored procedure that's stored and run on the database server.
    A prepared statement doesn't require a database stored procedure. It's parsed and cached by the JDBC driver, and allows you to specify parameters and bind values to them at runtime. Those are usually used in loop constructs where you want to repeatedly execute the same SQL with different values.
    Not all RDBMS support stored procedures (e.g., MySQL), but every driver I've used allows PreparedStatements. - MOD

  • Different between CallableStatement, PreparedStatement

    different between CallableStatement, PreparedStatement.

    One begins with Callable, one with Prepared.
    Can't you folks be bothered to read the API docs for Heaven's sake?

  • How to retrieve a SQL query (in String format) from a PreparedStatement

    Hello all,
    I am in the process of unit testing an application accessing a Oracle 9i 9.2 RDBMS server with JDBC.
    My query is:
    As I have access to PreparedStatement and CallableStatement Java objets but not to the source queries which help create those objects?
    Is thtere a simple way by using an API, to retrieve the SQL command (with possible ? as placeholders for parameters).
    I have already looked at the API documentation for those two objets (and for the Statement and ResultSetmetaData objects too) but to no avail.
    Thank you for any help on this issue,
    Best regards,
    Benoît

    Sorry for having wasted your time... and for not understanding what you meant in your first reply.
    But the codlet was only to show the main idea:
    Here is the code which compiles OK for this approach to reach its intended goal:
    main class (file TestSuiteClass.java):
    import java.sql.*;
    import static java.lang.Class.*;
    * Created by IntelliJ IDEA.
    * User: bgilon
    * Date: 15/03/12
    * Time: 10:05
    * To change this template use File | Settings | File Templates.
    public class TestSuiteClass {
    public static void main(final String[] args) throws Exception {
    // Class.forName("oracle.jdbc.OracleDriver");
    final Connection mconn= new mConnection(
    DriverManager.getConnection("jdbc:oracle:thin:scott/tiger@host:port:service"));
    * final Statement lstmt= TestedClass.TestedMethod(mconn, ...);
    * final String SqlSrc= mconn.getSqlSrc(lstmt).toUpperCase(), SqlTypedReq= mconn.getTypReq(lstmt);
    * assertEquals("test 1", "UPDATE IZ_PD SET FIELD1= ? WHERE FIELDPK= ?", SqlSrc);
    Proxy class (file mConnector.java):
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    * Created by IntelliJ IDEA.
    * User: bgilon
    * Date: 15/03/12
    * Time: 10:05
    * To change this template use File | Settings | File Templates.
    * This file should be compiled with JDK 1.6, but can be used with previous JDK versions.
    * See OKwith1pN booleans usage for not throwing Exceptions as Unknown methods by the conn object...
    public final class mConnection implements Connection {
    private final Connection conn;
    private final List<Statement> Stmts= new ArrayList<Statement>();
    private final List<String> SqlSrcs= new ArrayList<String>();
    private final List<Integer> TypSrcs= new ArrayList<Integer>();
    private final static String jvmv= System.getProperty("java.specification.version");
    private static final boolean OKwith1p2;
    private static final boolean OKwith1p4; /* OKwith1p5, */
    private static final boolean OKwith1p6;
    static {
    /* jvmv= System.getProperty("java.version");
    System.out.println("jvmv = " + jvmv);
    jvmv= System.getProperty("java.vm.version");
    System.out.println("jvmv = " + jvmv); */
    System.out.println("jvmv = " + jvmv);
    OKwith1p2= (jvmv.compareTo("1.2") >= 0);
    OKwith1p4= (jvmv.compareTo("1.4") >= 0);
    // OKwith1p5= (jvmv.compareTo("1.5") >= 0);
    OKwith1p6= (jvmv.compareTo("1.6") >= 0);
    public String getSqlSrc(final Statement pstmt) {
    int ix= 0;
    for(Statement stmt : this.Stmts) {
    if(stmt == pstmt) return SqlSrcs.get(ix);
    ix+= 1;
    return null;
    static private final String[] TypeNames= new String[] { "Statement", "PreparedStatement", "CallableStatement" };
    public String getTypReq(final Statement pstmt) {
    int ix= 0;
    for(Statement stmt : this.Stmts) {
    if(stmt == pstmt) return TypeNames[TypSrcs.get(ix)];
    ix+= 1;
    return null;
    private void storedStatement(
    final Statement stmt,
    final String sqlSrc,
    final Integer typReq
    Stmts.add(stmt);
    SqlSrcs.add(sqlSrc);
    TypSrcs.add(typReq);
    public Connection getDecoratedConn() {
    return conn;
    mConnection(final Connection pconn) {
    this.conn= pconn;
    public boolean isClosed() throws SQLException {
    return conn.isClosed();
    public void rollback(Savepoint savepoint) throws SQLException {
    if(OKwith1p4) conn.rollback(savepoint);
    public boolean isReadOnly() throws SQLException {
    return conn.isReadOnly();
    public int getTransactionIsolation() throws SQLException {
    return conn.getTransactionIsolation();
    public void setTransactionIsolation(int level)throws SQLException {
    conn.setTransactionIsolation(level);
    public Properties getClientInfo() throws SQLException {
    return OKwith1p6 ? conn.getClientInfo() : null;
    public <T> T unwrap(Class<T> iface)
    throws SQLException {
    return conn.unwrap(iface);
    public void setAutoCommit(boolean auto) throws SQLException {
    conn.setAutoCommit(auto);
    public boolean getAutoCommit() throws SQLException {
    return conn.getAutoCommit();
    public Map<String,Class<?>> getTypeMap() throws SQLException {
    if(!OKwith1p2) return null;
    return conn.getTypeMap();
    public void setTypeMap(Map<String,Class<?>> map) throws SQLException {
    if(!OKwith1p2) return;
    conn.setTypeMap(map);
    public void setHoldability(final int holdability) throws SQLException {
    if(OKwith1p4) conn.setHoldability(holdability);
    public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
    return conn.createStruct(typeName, attributes);
    public void commit() throws SQLException {
    conn.commit();
    public void rollback() throws SQLException {
    conn.rollback();
    public boolean isValid(int timeout) throws SQLException {
    return OKwith1p6 && conn.isValid(timeout);
    public void clearWarnings() throws SQLException {
    conn.clearWarnings();
    public int getHoldability() throws SQLException {
    if(!OKwith1p4) return -1;
    return conn.getHoldability();
    public Statement createStatement() throws SQLException {
    return conn.createStatement();
    public PreparedStatement prepareStatement(final String SqlSrc) throws SQLException {
    if(!OKwith1p2) return null;
    final PreparedStatement lstmt= conn.prepareStatement(SqlSrc);
    storedStatement(lstmt, SqlSrc, 1);
    return lstmt;
    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
    if(!OKwith1p4) return null;
    final PreparedStatement lstmt= conn.prepareStatement(sql, columnNames);
    storedStatement(lstmt, sql, 1);
    return lstmt;
    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
    final PreparedStatement lstmt= conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
    storedStatement(lstmt, sql, 1);
    return lstmt;
    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
    final PreparedStatement lstmt= conn.prepareStatement(sql, columnIndexes);
    storedStatement(lstmt, sql, 1);
    return lstmt;
    public void setClientInfo(String name, String value) throws SQLClientInfoException {
    if(OKwith1p6)
    conn.setClientInfo(name, value);
    public PreparedStatement prepareStatement(final String SqlSrc,
    int resultType,
    int resultSetCurrency,
    int resultSetHoldability) throws SQLException {
    final PreparedStatement lstmt= conn.prepareStatement(SqlSrc, resultType, resultSetCurrency);
    storedStatement(lstmt, SqlSrc, 1);
    return lstmt;
    public PreparedStatement prepareStatement(final String SqlSrc,
    int autogeneratedkeys) throws SQLException {
    if(!OKwith1p4) return null;
    final PreparedStatement lstmt= conn.prepareStatement(SqlSrc, autogeneratedkeys);
    storedStatement(lstmt, SqlSrc, 1);
    return lstmt;
    public CallableStatement prepareCall(final String SqlSrc) throws SQLException {
    final CallableStatement lstmt= conn.prepareCall(SqlSrc);
    storedStatement(lstmt, SqlSrc, 2);
    return lstmt;
    public CallableStatement prepareCall(final String SqlSrc,
    int resultType,
    int resultSetCurrency,
    int resultSetHoldability) throws SQLException {
    if(!OKwith1p4) return null;
    final CallableStatement lstmt= conn.prepareCall(SqlSrc, resultType, resultSetCurrency, resultSetHoldability);
    storedStatement(lstmt, SqlSrc, 2);
    return lstmt;
    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
    return OKwith1p6 ? conn.createArrayOf(typeName, elements) : null;
    public CallableStatement prepareCall(final String SqlSrc,
    int resultType,
    int resultSetCurrency) throws SQLException {
    if (!OKwith1p2) return null;
    final CallableStatement lstmt= conn.prepareCall(SqlSrc, resultType, resultSetCurrency);
    storedStatement(lstmt, SqlSrc, 2);
    return lstmt;
    public SQLXML createSQLXML() throws SQLException {
    return OKwith1p6 ? conn.createSQLXML() : null;
    public DatabaseMetaData getMetaData() throws SQLException {
    return conn.getMetaData();
    public String getCatalog() throws SQLException {
    return conn.getCatalog();
    public void setCatalog(final String str) throws SQLException {
    conn.setCatalog(str);
    public void setReadOnly(final boolean readonly) throws SQLException {
    conn.setReadOnly(readonly);
    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
    if(!OKwith1p2) return null;
    return conn.createStatement(resultSetType, resultSetConcurrency);
    public String nativeSQL(final String sql) throws SQLException {
    return conn.nativeSQL(sql);
    public void     releaseSavepoint(Savepoint savepoint) throws SQLException {
    if(OKwith1p4) conn.releaseSavepoint(savepoint);
    public Savepoint setSavepoint() throws SQLException {
    return OKwith1p4 ? conn.setSavepoint() : null;
    public Savepoint setSavepoint(final String str) throws SQLException {
    return OKwith1p4 ? conn.setSavepoint(str) : null;
    public boolean isWrapperFor(Class iface) throws SQLException {
    return conn.isWrapperFor(iface);
    public String getClientInfo(final String str) throws SQLException {
    return OKwith1p6 ? conn.getClientInfo(str) : null;
    public void setClientInfo(final Properties pro) throws SQLClientInfoException {
    if (OKwith1p6) conn.setClientInfo(pro);
    public Blob createBlob() throws SQLException {
    return OKwith1p6 ? conn.createBlob() : null;
    public Clob createClob() throws SQLException {
    return OKwith1p6 ? conn.createClob() : null;
    public NClob createNClob() throws SQLException {
    return OKwith1p6 ? conn.createNClob() : null;
    public SQLWarning getWarnings() throws SQLException {
    return conn.getWarnings();
    public void close() throws SQLException {
    conn.close();
    Final word:
    The final word about this is: there is currently three ways to obtain source SQL queries from compiled statement objects.
    a) Use a proxy class the mConnector above;
    b) Use a proxy JDBC driver as Log4JDBC;
    c) Use the trace facility of the driver (however, post analyzing the logs would depend upon the driver selected).
    Thank you for reading,
    Benoît

  • 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!
    - Saish

    I 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

  • Problem in using BLOB and callablestatement

    Hi
    I am doing an insert into the database , of which one of the clomn is
    BLOB
    when i do it using prepared statement , it does it fine
    but if i do it using the callable statment (Stored procedure)its not
    doing it .....
    and gives an error like below
    does anybod know what the problem is
    java.sql.SQLException: ORA-06550: line 1, column 9:
    PLS-00306: wrong number or types of arguments in call to 'IN
    SERT_EVENT_LOG'
    ORA-06550: line 1, column 9:
    PL/SQL: Statement ignored
    at weblogic.db.oci.OciCursor.getCDAException(OciCurs
    or.java:228)
    at weblogic.jdbcbase.oci.Statement.executeUpdate(Sta
    tement.java:869)
    at weblogic.jdbc20.pool.PreparedStatement.executeUpd
    ate(PreparedStatement.java:47)
    at weblogic.jdbc20.rmi.internal.PreparedStatementImp
    l.executeUpdate(PreparedStatementImpl.java:54)
    at weblogic.jdbc20.rmi.SerialPreparedStatement.execu
    teUpdate(SerialPreparedStatement.java:55)
    at com.expertcommerce.core.log.DatabaseLogService.in
    ternalLog(DatabaseLogService.java:73)
    at com.expertcommerce.core.log.BaseLogService.log(Ba
    seLogService.java:33)
    at com.expertcommerce.core.log.biz.ServerLogAdapter.
    log(ServerLogAdapter.java:113)
    at com.expertcommerce.core.log.biz.ServerLogAdapter.
    logError(ServerLogAdapter.java:135)
    at com.expertcommerce.core.users.biz.UserEntityBean.
    ejbFindByPrimaryKey(UserEntityBean.java:409)
    at com.expertcommerce.core.users.biz.UserEntityBeanH
    omeImpl.findByPrimaryKey(UserEntityBeanHomeImpl.java:81)
    at com.expertcommerce.core.users.biz.UserEntityBeanH
    omeImpl.findByPrimaryKey(UserEntityBeanHomeImpl.java:49)
    at weblogic.ejb.internal.EJBHomeImpl.remove(EJBHomeI
    mpl.java:297)
    at com.expertcommerce.core.users.biz.UserEntityBeanH
    omeImpl_ServiceStub.remove(UserEntityBeanHomeImpl_ServiceStu
    b.java:378)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBean.removeUser(UserManagerSessionBean.java:172)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBean.handle(UserManagerSessionBean.java:47)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBeanEOImpl.handle(UserManagerSessionBeanEOImpl.java:146)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBeanEOImpl_ServiceStub.handle(UserManagerSessionBeanEOImp
    l_ServiceStub.java:255)
    at com.expertcommerce.core.event.CoreEventDispatcher
    .dispatch(CoreEventDispatcher.java:17)
    at com.expertcommerce.core.event.biz.CoreEventDispat
    cherSessionBean.dispatch(CoreEventDispatcherSessionBean.java
    :24)
    at com.expertcommerce.core.event.biz.CoreEventDispat
    cherSessionBeanEOImpl.dispatch(CoreEventDispatcherSessionBea
    nEOImpl.java:105)
    at com.expertcommerce.core.event.biz.CoreEventDispat
    cherSessionBeanEOImpl_WLSkel.invoke(CoreEventDispatcherSessi
    onBeanEOImpl_WLSkel.java:159)
    at weblogic.rmi.extensions.BasicServerObjectAdapter.
    invoke(BasicServerObjectAdapter.java:338)
    at weblogic.rmi.extensions.BasicRequestHandler.handl
    eRequest(BasicRequestHandler.java:69)
    at weblogic.rmi.internal.BasicExecuteRequest.execute
    (BasicExecuteRequest.java:15)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.j
    ava:120)
    com.expertcommerce.core.log.LogServiceException: ORA-06550:
    line 1, column 9:
    PLS-00306: wrong number or types of arguments in call to 'IN
    SERT_EVENT_LOG'
    ORA-06550: line 1, column 9:
    PL/SQL: Statement ignored
    at com.expertcommerce.core.log.DatabaseLogService.in
    ternalLog(DatabaseLogService.java:111)
    at com.expertcommerce.core.log.BaseLogService.log(Ba
    seLogService.java:33)
    at com.expertcommerce.core.log.biz.ServerLogAdapter.
    log(ServerLogAdapter.java:113)
    at com.expertcommerce.core.log.biz.ServerLogAdapter.
    logError(ServerLogAdapter.java:135)
    at com.expertcommerce.core.users.biz.UserEntityBean.
    ejbFindByPrimaryKey(UserEntityBean.java:409)
    at com.expertcommerce.core.users.biz.UserEntityBeanH
    omeImpl.findByPrimaryKey(UserEntityBeanHomeImpl.java:81)
    at com.expertcommerce.core.users.biz.UserEntityBeanH
    omeImpl.findByPrimaryKey(UserEntityBeanHomeImpl.java:49)
    at weblogic.ejb.internal.EJBHomeImpl.remove(EJBHomeI
    mpl.java:297)
    at com.expertcommerce.core.users.biz.UserEntityBeanH
    omeImpl_ServiceStub.remove(UserEntityBeanHomeImpl_ServiceStu
    b.java:378)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBean.removeUser(UserManagerSessionBean.java:172)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBean.handle(UserManagerSessionBean.java:47)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBeanEOImpl.handle(UserManagerSessionBeanEOImpl.java:146)
    at com.expertcommerce.core.users.biz.UserManagerSess
    ionBeanEOImpl_ServiceStub.handle(UserManagerSessionBeanEOImp
    l_ServiceStub.java:255)
    at com.expertcommerce.core.event.CoreEventDispatcher
    .dispatch(CoreEventDispatcher.java:17)
    at com.expertcommerce.core.event.biz.CoreEventDispat
    cherSessionBean.dispatch(CoreEventDispatcherSessionBean.java
    :24)
    at com.expertcommerce.core.event.biz.CoreEventDispat
    cherSessionBeanEOImpl.dispatch(CoreEventDispatcherSessionBea
    nEOImpl.java:105)
    at com.expertcommerce.core.event.biz.CoreEventDispat
    cherSessionBeanEOImpl_WLSkel.invoke(CoreEventDispatcherSessi
    onBeanEOImpl_WLSkel.java:159)
    at weblogic.rmi.extensions.BasicServerObjectAdapter.
    invoke(BasicServerObjectAdapter.java:338)
    at weblogic.rmi.extensions.BasicRequestHandler.handl
    eRequest(BasicRequestHandler.java:69)
    at weblogic.rmi.internal.BasicExecuteRequest.execute
    (BasicExecuteRequest.java:15)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.j
    ava:120)
    with parameter
    exitsfalse
    Retuening result to CoreEventcom.expertcommerce.core.users.e
    vents.RemoveUserEvent@6dcc33
    Stored Procedure .....
    CREATE or replace procedure insert_Event_Log
    pEvent_ID in out number,
    pEvent_Severity in number,
    pEvent_Data in blob,
    pEvent_Action in number,
    pEvent_Time in date,
    pEvent_Source in char,
    pEvent_Status in char,
    pEvent_User in char,
    pEvent_Subject in char,
    pEvent_Subject_ID in char
    AS
    tEvent_ID number;
    BEGIN
    /* Get the sequence key */
    if (pEvent_ID is null ) then
    select event_id_seq.nextval into tEvent_ID from dual;
    insert into Event_ID (pkey, justabit) values ( tEvent_ID, 1);
    end if;
    /* Insert the values in the table */
    INSERT INTO Event_Log
    Event_ID,
    Event_Severity,
    Event_Data,
    Event_Action,
    Event_Time,
    Event_Source,
    Event_Status,
    Event_User,
    Event_Subject,
    Event_Subject_ID
    VALUES (
    tEvent_ID,
    pEvent_Severity,
    pEvent_Data,
    pEvent_Action,
    pEvent_Time,
    pEvent_Source,
    pEvent_Status,
    pEvent_User,
    pEvent_Subject,
    pEvent_Subject_ID
    pEvent_ID := tEvent_ID;
    END;
    My TEst Program
    import java.sql.*;
    import java.util.Properties;
    import oracle.jdbc.driver.*;
    import oracle.sql.*;
    class rfxtest{
    public static void main(String[] args){
    rfxtest test = new rfxtest();
    CallableStatement m_stmt = null;
    PreparedStatement pStmt = null;
    String rfxdata = "this is the test data for the event-blob-test";
    try{
    Connection con = test.getConnection();
    String temp = "call insert_event_log ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    m_stmt = con.prepareCall(temp);
    m_stmt.setNull(1, java.sql.Types.INTEGER);
    m_stmt.setInt(2, 123);
    m_stmt.setBytes(3, (byte[])rfxdata.getBytes());
    m_stmt.setInt(4, 123);
    m_stmt.setTimestamp(5, new java.sql.Timestamp(System.currentTimeMillis()));
    m_stmt.setString(6, "xxxxxxxxxx");
    m_stmt.setString(7, "xxxxxxxxxx");
    m_stmt.setString(8, "xxxxxxxxxx");
    m_stmt.setString(9, "xxxxxxxxxx");
    m_stmt.setString(10, "xxxxxxxxxx");
    m_stmt.executeUpdate();
    String selectStmt = " select event_data from event_log where event_id = 12345" ;
    pStmt = con.prepareStatement(selectStmt);
    ResultSet rs = pStmt.executeQuery();
    if(!rs.next()){
    System.out.println("error");
    } else {
    Blob b = rs.getBlob(1);
    byte[] blob = (byte[])b.getBytes(1,(int)b.length());
    String s = new String(blob);
    System.out.println("The blob content is : "+s);
    }catch(Exception e){
    e.printStackTrace();
    public Connection getConnection(){
    try{
    Properties props = new Properties();
    props.put("user", "nexgen");
    props.put("password", "nexgen");
    Driver myDriver = (Driver) new oracle.jdbc.driver.OracleDriver();
    Connection conn =
    myDriver.connect("jdbc:oracle:thin:@192.168.254.6:1521:ecw",props);
    return conn;
    catch(Exception e){
    e.printStackTrace();
    return null;
    appreciate response
    venki
    null

    Navid,
    JHeadstart checks whether the attribute definition is queryable before adding it to the list of advanced search attributes. A transient VO attribute can still be set to queryable, for a transient EO attribute this is not possible. We will remove this check on queryability in the upcoming patch release, since you have a valid use case. For now, you can subclass JhsSearchBean and override method createArgumentListForAdvancedSearch and comment out the check for "def.isQueryable()".
    Steven Davelaar,
    JHeadstart Team.

  • Gettig SQLException while using CallableStatement

    Hi,
    I am using Oracle 10 G JDBC Release 10.2.0.1.0 (ojdbc14.jar), I am getting SQLException while fetching next record from the resultset returned by a PLSQL procedure.The same code is working fine with classes12_g.jar
    Here is the code,
              CallableStatement cStat = null;
              PreparedStatement stat1 = null;
              Connection con = null;
              String decryptedPassword     =     null;
              boolean isPasswordExpiryDateValid     =     false;
              String message     =     "";
              boolean authenticated     =     false;
              boolean passwordExpired     =     false;
              HashMap hashMap     =     new HashMap();
              ResultSet callRs = null;
              try
                   con = getConnection();
                   cStat = con.prepareCall("{? = call passWd.decrypt_password(?, 'JPRAXISPASS')}");
                   cStat.registerOutParameter(1, java.sql.Types.VARCHAR);
                   cStat.setString(2, encryptedPassword);
                   callRs = cStat.executeQuery();
                   if(callRs.next())               {
                        decryptedPassword = cStat.getString(1);
    I am getting follwing SQLException
    java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next is thrown when I try to fetch next record at line
    if(callRs.next())
    Please suggest the solution,
    Thanks and Regards,
    Rajendra Doulaghar

    Hi,
    First, execute() is recommended for CallableStatement.
    Second, with Oracle atabase, PL/SQL returns a Ref Cursor, not a result set; you need to invoke getCursor() on the returned object from PL/SQL to turn it into a result set then you cnatreat it as a regular result set.
    Kuassi, http://db360.blogspot.com/

  • PreparedStatement vs Statement & OCI vs thin

    http://www.oreilly.com/catalog/jorajdbc/chapter/ch19.html
    came accross this sample chapter from a book which compares Statement vs PreparedStatement vs CallableStatement (and all of the aforementioned using both the thin and OCI drivers for Oracle)
    Just wondering if anyone had read the book. It was published in Dec 2001 so the results should be current. If anyone has read it, let me know what you think.
    I haven't found many reliable benchmarks for database access, but this one compares only Oracle implementations so I have to assume that it is unbiased. (not the usual "my drivers are better than my competitions - benchmarks to prove it"... then you check out the competition and it says "my drivers are the fastest - benchmarks to prove it!")
    Jamie

    I haven't read this book, but from other sources and my own experience the basic rules are as follows:
    - PreparedStatement is faster then Statement if the SQL statemtn is rather complex and used frequently
    - OCI is generally faster than Thin, but requires more setup on the client
    as always, these rules have exceptions, and the only way to find out is to try with your program.

Maybe you are looking for

  • How Do I Open The Excel Spreadshee​t And Modify The Cell Data

    How can I change the cell content in specific excel spreadsheet with ActiveX control? I am using LabVIEW7.1

  • Groupping functions in BI7

    could you please let me know groupping functions in BI7 ?' what is it's significance and how it works in BI7 ? Thanks Regards

  • How to make selection on JComboBox.

    Dear all, I want to make condition on basis of selection of JComboBox. Any one have code of such scenrio. Thanks in advance.

  • Error message and shut down

    While watching a youtube video an error messgae came up saying that Inneed to shut mac down Accompanied by a loud beeping sound. I have restarted Mac using safe mode, normal and with snow leopard disk and sometimes I get a blue screen. Other times I

  • Captivate 6 crashes when "edit in audition" button is clicked.

    Captivate 6 crashes every time I click the edit in audition button. What Ive tried: Different projects- same result Delete pref folder - same result Remove and reinstall CP6 and 6.1 patch- same result Disconnect second monitor and run the the above-