Calling stored procedures in Sybase from java

Hi,
I am using the following stored procedure in Sybase
use xyzdb
go
-- drop procedure if it already exist
if object_id('up_name_select') is not null
begin
drop procedure up_name_select
end
go
create procedure up_name_select
@zid          numeric(7,0),
@firstname     char(40),
@lastname     char(40)
as
select zid,
firstname,
lastname
from name
where zid = @zid or
(lastname like @lastname or firstname like @firstname)
go
-- update documentation records in object_docs
delete object_docs
from object_docs
where object_name = "up_name_select"
go
insert into object_docs values("up_name_select","Selects records from the name table based upon the values of the input parameters.")
go
-- update documentation records in column_docs
delete column_docs
from column_docs
where object_name = "up_name_select"
go
insert into column_docs values("up_name_select","@zid","System generated ID for an individual contact.")
insert into column_docs values("up_name_select","@firstname","First name of the contact. SQL wild card characters are accepted.")
insert into column_docs values("up_name_select","@lastname","Last name of the contact. SQL wild card characters are accepted.")
go
-- print success message and grant permissions
if object_id('up_name_select') is not null
begin
print "Procedure up_name_select created."
grant execute on up_name_select to developer_role
end
go
This stored procedure selects the values from the table "name" for a given where condition (if I am not wrong).
Can any one give me sample java code to select the records from the table "name" for a given zid.
Thankyou in advance.
Regards
sgatl2

calling stored procedures from java
here is the sample code
CallableStatement cs = con.prepareCall("{call selectlogin (?)}");
cs.setString (1, "value");         
ResultSet rs = cs.executeQuery ();
            while (rs.next ())
            //your code for display
            } more on gooooooogle
http://www.google.com/search?q=calling+stored+procedures+from+java+with+sample+example&client=netscape-pp&rls=com.netscape:en-US

Similar Messages

  • Without calling stored procedure or functions from database

    Hi,
    I am using Jdeveloper 11.1.1.5.0.
    =>How to do PL/SQL procedures and functions in ADF without calling stored procedure or function from DB?

    S, PL/SQL procedures and functions are done in Application Module class or in managed bean..By calling the stored procedures or functions from DB.
    But I am asking how to do if DB doesn't have any procedures,triggers and functions.

  • CALLING STORED PROCEDURE IN DATABASE FROM FORMS4.5

    Is there any body know how to call stored procedure from Forms 4.5 ?
    I am writing a when-button-pressed trigger.
    Put the stored procedure name on there. But
    it said "stored procedure name is not declared on this scope".
    Thanks a lot
    null

    Try logging in to SQL*Plus and running the procedure, e.g....
    SQL> begin
    database_procedure_name(update_web);
    end;
    If it runs OK there, then it should run from within your form (provided that you are logged in as the same user as the test with SQL*Plus.

  • How to call stored procedure in SYBASE using callable statement

    Hi all,
    Im using jdbc code to execute a stored procedure in sybase but while running the code i get an error saying
    java.sql.SQLException: JZ0R2: No result set for this query.
    at com.sybase.jdbc2.jdbc.ErrorMessage.raiseError(ErrorMessage.java:506)
    at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybStatement.java:1552)
    at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1522)
    at com.sybase.jdbc2.jdbc.SybCallableStatement.executeQuery(SybCallableStatement.java:76)
    but when i execute the same procedure in sybase it returns some result but i know its not in resultset format .I want to know is anyone experienced same problem in their side.
    My question is how to obtain the result which is not in the format result set obtained by executing the stored procedure.
    Thanks n advance
    work machine

    Check this post out:
    http://forum.java.sun.com/thread.jspa?threadID=638768&messageID=3785982
    But I think you should be getting results right? What do you mean you want it in a format other than resultset?

  • Calling Stored Procedure with Paramters in Java

    Hi
    I havent done alot of sql/java work so I'm wondering if I could get some help.
    I have the java code
    private void processPatient(Element pat)
    throws PatientException,
    ParseException,
    SQLException,
    Exception {
    Connection con = null;
    ResultSet rs;
    CallableStatement cs;
    ...<code>
    cs = con.prepareCall("{call updt_pat.set_pat_ppe}");
    rs = cs.executeQuery();
    Does this look correct? The proc updt_pat.set_pat_ppe also takes an int parameter...how would I modify this to accept the paramter? Like
    cs = con.prepareCall("{call updt_pat.set_pat_ppe paramter}");
    Thanks for the help!!
    Mani

    The actual implementation of what the setInt does and how it does it is up the JDBC driver vendor. Basically its function is as follows (implementation will be driver specific) it takes the int value and passes it to the Stored Procedure being called as the (in this case) 1st input parameter expected by the stored procedure. Whatever the name of the IN variable is within the stored procedure is irrelevant to the JDBC code, basically it will be assigned to the name of the first IN parameter within the Stored Procedure.
    The error you are reporting:
    xxx.java:272: cannot resolve symbol
    symbol : method setInt (java.lang.Integer,int)
    location: interface java.sql.CallableStatement
    cs.setInt(1, ppath.getPatId());
    ^
    1 error
    is interesting as it is claiming that the setInt method requires as its first argument an Integer object - this is not what the specification requires, it just wants an index number as a Java int:
    setInt(int index, int value), note no java.lang.Integer
    maybe this is a driver specific implementation?
    Try the following (not in any specific order):
    1 - int value = ppath.getPatId();
    cs.setInt(1, value);
    2 - Integer index = new Integer(1);
    cs.setInt(index , ppath.getPatId());
    3 - int = ppath.getPatId();
    Integer index = new Integer(1);
    cs.setInt(index , value);
    Let me know if this solves your problem.

  • Calling Stored Procedure with parameters from a C program

    Hello, I need to call a PL/SQL stored procedure from a C program.
    Something like this sample program provided by Oracle -
    main()
    int i;
    EXEC SQL BEGIN DECLARE SECTION;
    */* Define type for null-terminated strings. */*
    EXEC SQL TYPE asciz IS STRING(20);
    asciz  username[20];
    asciz  password[20];
    int    dept_no;    / which department to query */*
    char   emp_name[10][21];
    char   job[10][21];
    EXEC SQL VAR emp_name is STRING (21);
    EXEC SQL VAR job is STRING (21);
    float  salary[10];
    int    done_flag;
    int    array_size;
    int    num_ret;    / number of rows returned */*
    int    SQLCODE;
    EXEC SQL END DECLARE SECTION;
    */* Connect to Oracle. */*
    strcpy(username, "SCOTT");
    strcpy(password, "TIGER");
    EXEC SQL WHENEVER SQLERROR DO sqlerror();
    EXEC SQL CONNECT :username IDENTIFIED BY :password;
    printf("Enter department number: ");
    scanf("%d", &dept_no);
    fflush(stdin);
    */* Set the array size. */*
    array_size = 10;
    done_flag = 0;
    num_ret = 0;
    */* Array fetch loop - ends when NOT FOUND becomes true. */*
    EXEC SQL EXECUTE
    BEGIN personnel.get_employees
    *(:dept_no, :array_size, :num_ret, :done_flag,*
    *:emp_name, :job, :salary);*
    END;
    END-EXEC;
    The question is - how is the Stored procedure get_employees declared ? Or more specifically, how is the salary parameter declared in get_employees ? Any help is highly appreciated.

    Hope following will help
    NOTE: Not tested
    Calling a stored procedure
    This program connects to ORACLE using the SCOTT/TIGER
    account. The program declares several host arrays, then
    calls a PL/SQL stored procedure (GET_EMPLOYEES in the
    CALLDEMO package) that fills the table OUT parameters. The
    PL/SQL procedure returns up to ASIZE values.
    It keeps calling GET_EMPLOYEES, getting ASIZE arrays
    each time, and printing the values, until all rows have been
    retrieved. GET_EMPLOYEES sets the done_flag to indicate "no
    more data."
    #include <stdio.h>
    #include <string.h>
    EXEC SQL INCLUDE sqlca.h;
    typedef char asciz[20];
    typedef char vc2_arr[11];
    EXEC SQL BEGIN DECLARE SECTION;
    /* User-defined type for null-terminated strings */
    EXEC SQL TYPE asciz IS STRING(20) REFERENCE;
    /* User-defined type for a VARCHAR array element. */
    EXEC SQL TYPE vc2_arr IS VARCHAR2(11) REFERENCE;
    asciz username;
    asciz password;
    int dept_no; /* which department to query? */
    vc2_arr emp_name[10]; /* array of returned names */
    vc2_arr job[10];
    float salary[10];
    int done_flag;
    int array_size;
    int num_ret; /* number of rows returned */
    EXEC SQL END DECLARE SECTION;
    long SQLCODE;
    void print_rows(); /* produces program output */
    void sql_error(); /* handles unrecoverable errors */
    main()
    int i;
    char temp_buf[32];
    /* Connect to ORACLE. */
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    strcpy(username, "scott");
    strcpy(password, "tiger");
    EXEC SQL CONNECT :username IDENTIFIED BY :password;
    printf("\nConnected to ORACLE as user: %s\n\n", username);
    printf("Enter department number: ");
    gets(temp_buf);
    dept_no = atoi(temp_buf);/* Print column headers. */
    printf("\n\n");
    printf("%-10.10s%-10.10s%s\n", "Employee", "Job", "Salary");
    printf("%-10.10s%-10.10s%s\n", "--------", "---", "------");
    /* Set the array size. */
    array_size = 10;
    done_flag = 0;
    num_ret = 0;
    /* Array fetch loop.
    * The loop continues until the OUT parameter done_flag is set.
    * Pass in the department number, and the array size--
    * get names, jobs, and salaries back.
    for (;;)
    EXEC SQL EXECUTE
    BEGIN calldemo.get_employees
    (:dept_no, :array_size, :num_ret, :done_flag,
    :emp_name, :job, :salary);
    END;
    END-EXEC;
    print_rows(num_ret);
    if (done_flag)
    break;
    /* Disconnect from the database. */
    EXEC SQL COMMIT WORK RELEASE;
    exit(0);
    void
    print_rows(n)
    int n;
    int i;
    if (n == 0)
    printf("No rows retrieved.\n");
    return;
    for (i = 0; i < n; i++)
    printf("%10.10s%10.10s%6.2f\n",
    emp_name, job[i], salary[i]);
    /* Handle errors. Exit on any error. */
    void
    sql_error()
    char msg[512];
    int buf_len, msg_len;
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    buf_len = sizeof(msg);
    sqlglm(msg, &buf_len, &msg_len);
    printf("\nORACLE error detected:");
    printf("\n%.*s \n", msg_len, msg);
    EXEC SQL ROLLBACK WORK RELEASE;
    exit(1);
    Remember, the datatype of each actual parameter must be convertible to the datatype of its corresponding formal parameter. Also, before a stored procedure is exited, all OUT formal parameters must be assigned values. Otherwise, the values of corresponding actual parameters are indeterminate.
    SQLCHECK=SEMANTICS is required when using an anonymous PL/SQL block.

  • How to call sql procedure with parameter from java

    Hello,
    i am trying to call one sql procedure with two parameters from java.
    the first parameter is In parameter, the second is OUT.
    the return value of this java method should be this second parameter value.
    the following is my java code:
    protected String getNextRunNumber() {
         String runnumber=null;
         String sql = "{call APIX.FNC_SST_EXPORT.GET_NEXT_RUNNUMBER (?,?)}";
    CallableStatement state = null;
    try{
         Connection con= getDatabaseConnection();
         state = con.prepareCall(sql);
         state.setString(1, m_appKeyExport);
         state.registerOutParameter(2,Types.NUMERIC,0);
         state.execute();
    ResultSet resultR = (ResultSet)state.getObject(2);
         while (resultR.next()) {
              runnumber=resultR.getBigDecimal(1).toString();
    catch (SQLException e){System.out.println("You can not get the export next run number properly");}
    return runnumber;
    i got error message like:
    java.lang.ClassCastException: java.math.BigDecimal
    As far as i knew, if the parameter is number or decimal, we should give also the paramer scale to the method: state.registerOutParameter(), but i still get this error message.
    Please help me to solve this problem.
    Thanks a lot.

    state.execute();
    i try to use debug to find the problem, in this line, i saw
    OracleCallableStatement(OraclePreparedStatement).execute() line: 642 [local variables unavailable]
    is this the problem?

  • Passing of ResultSet to Stored Procedure(Oracle 8i)  from Java

    My requirement is such that I want to send a resultset to a stored procedure(In oracle8i). Through Java API's.
    The input parameter to the PLSQL is a ref cursor.
    I am trying to send the resultSet using CallableStatement of java but it is throwing an Inavlid column type error.
    So firstly is it possible to send a resultset to Oracle through java. If yes, then please suggest me as to how it can be done?

    Rajeev,
    I remember seeing something on Oracle's MetaLink Web site, saying that this is not supported. Sorry, but I can't give you any more details -- I don't remember (and I'm too lazy to look :-)
    I also think that I found that MetaLink article via a posting to one of these (i.e. Oracle) forums. Perhaps a search of the forum archives will help?
    Good Luck,
    Avi.

  • Calling a SP or Function from Java receiving a geometry(MDSYS.SDO_GEOMETRY)

    Hi there,
    What I want to do is: calling a stored procedure OR function from Java with a String-variable as input and receiving a geometry (SDO_GEOMETRY).
    I’m facing currently the problem of calling a stored function on oracle 11g from Java using JPA (EclipseLink), Spring 2.5.6 returning an MDSYS.SDO_GEOMETRY object.
    I’ve tried to call a stored procedure with MDSYS.SDO_GEOMETRY as an output parameter instead, but with no success.
    The function’s signature looks like this:
    CREATE or REPLACE
    FUNCTION GET_GEO_BRD_FUNCTION(p_geo_brd_id IN VARCHAR2) RETURN MDSYS.SDO_GEOMETRY AS
    sdo_geom    MDSYS.SDO_GEOMETRY := null;
    BEGIN
    /* do some fancy stuff on the database side */
      SELECT sp_geom
        INTO sdo_geom
        FROM geo_brd WHERE id = p_geo_brd_id;
      RETURN sdo_geom;
    END;
    The calling code looks like this:
    MyClass extends JpaDaoSupport{
       /** logger */
       protected static final ILogger LOG = LogFactory.getLogger(MyClass.class);
        * {@inheritDoc}
        * @see com.example.MyClass#calculateGeometry(java.lang.String)
       @Override
       public JGeometry calculateGeometry(final String id) {
           JGeometry geometry = null;
           final JpaCallback action = new JpaCallback() {
                @Override
                public Object doInJpa(final EntityManager em) throws PersistenceException {
                   final Session session = JpaHelper.getEntityManager(em).getActiveSession();
                   final StoredFunctionCall functionCall = new StoredFunctionCall();
                   functionCall.setProcedureName("GET_GEO_BRD_FUNCTION");
                   functionCall.addNamedArgument("p_geo_brd_id");
                   functionCall.setResult("sdo_geom", Oracle.sql.STRUCT.class);
                   final ValueReadQuery query = new ValueReadQuery();
                   query.setCall(functionCall);
                   query.addArgument("p_geo_brd_id");
                   final ArrayList args = new ArrayList();
                   args.add("2e531e62-2105-4522-978a-ab8baf19e273");// hardcoded for test
                   final Object result = session.executeQuery(query, args);
                   return result;
        final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);
        try {
           geometry = JGeometry.load(result);
        } catch (final SQLException e) {
           MyClass.LOG.error("Error loading JGeometry from STRUCT.", e);
           return null;
        return geometry;
    And when I execute the query I get the following error:
    Internal Exception: java.sql.SQLException: ORA-06550: Row 1, Column 13:
    PLS-00382: expression is of wrong type
    ORA-06550: Row 1, Column 7:
    PL/SQL: Statement ignored
    Error Code: 6550
    Call: BEGIN ? := GET_GEO_BRD_FUNCTION(p_geo_brd_id=>?); END;
         bind => [=> sdo_geom, 2e531e62-2105-4522-978a-ab8baf19e273]
    Query: ValueReadQuery()
    So I thought may be let's try it with a stored procedure instead...
    The procedure looks like this:
    CREATE or REPLACE
    PROCEDURE GET_GEO_BRD_PROCEDURE(p_geo_brd_id IN VARCHAR2, sdo_geom OUT MDSYS.SDO_GEOMETRY) AS
    BEGIN
    /* do some fancy stuff on the database side */
      SELECT sp_geom
        INTO sdo_geom
        from geo_brd where id = p_geo_brd_id;
    END;
    The calling Java code in case of the stored procedure looks like this (only the content of the JPACallback has changed):
    @Override
    public Object doInJpa(final EntityManager em) throws PersistenceException {
        final Session session = JpaHelper.getEntityManager(em).getActiveSession();
        final StoredProcedureCall spCall = new StoredProcedureCall();
        spCall.setProcedureName("GET_GEO_BRD_PROCEDURE");
        spCall.addNamedArgument("p_geo_brd_id", "p_geo_brd_id", String.class);
        spCall.addNamedOutputArgument("sdo_geom", "sdo_geom", OracleTypes.STRUCT);
        final ValueReadQuery query = new ValueReadQuery();
        query.setCall(spCall);
        query.addArgument("p_geo_brd_id"); // input
        final List args = new ArrayList();
        args.add("2e531e62-2105-4522-978a-ab8baf19e273");// hardcoded for test
        final Object result = session.executeQuery(query, args);
        return result;
    And when I execute the query I get the following error:
    java.sql.SQLException: ORA-06550: Row 1, Column 13:
    PLS-00306: wrong number or types of arguments in call to 'GET_GEO_BRD_PROCEDURE'
    ORA-06550: Row 1, Column 7:
    PL/SQL: Statement ignored
    So both exceptions look quite similar.
    I guess in both cases the exception description leads to the assumption, that the wrong type for the return value / output parameter is used…
    So - how can a receive a MDSYS_SDO_GEOMETRY object from a stored procedure or stored function in Java ?
    What is wrong in the Java code?
    Thank you in advance for any suggestions!
    Yours,
    Chris
    Edited by: user3938161 on 20.12.2011 07:46
    Edited by: user3938161 on Dec 20, 2011 8:06 AM: added variable declaration of JGeometry geometry in source code

    Thanks, that did the trick! ;-)
    Here is now the code for stored procedure and function for anybody else encountering the same troubles... (be aware of the parameter order and/or naming!)
    Code for stored functions:
    final JpaCallback action = new JpaCallback() {
      @Override
      public Object doInJpa(final EntityManager em) throws PersistenceException {
         final Session session = JpaHelper.getEntityManager(em).getActiveSession();
           * Using CallableStatement for stored functions
          STRUCT st = null;
          CallableStatement cs = null;
          final DatabaseLogin login = session.getLogin();
          final Connection _conn = (Connection) login.connectToDatasource(session.getDatasourceLogin().buildAccessor(), session);
          try {
             try {
                cs = _conn.prepareCall("{? = call GET_GEO_BRD_FUNCTION(?)}");
                cs.registerOutParameter(1, OracleTypes.STRUCT, "MDSYS.SDO_GEOMETRY");
                cs.setString(2, "2e531e62-2105-4522-978a-ab8baf19e273");//TODO: hardcoded for test
                cs.execute();
             } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured calling the stored procedure", e);
             if (cs != null) {
                //reading geometry from the database
                try {
                   st = (STRUCT) cs.getObject(1);
                } catch (final SQLException e) {
                   MyClass.LOG.error("An exception occured converting the query result to oracle.sql.STRUCT", e);
          } finally {
             try {
                if (_conn != null && !_conn.isClosed()) {
                    _conn.close();
             } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured on closing the database connection.", e);
          return st;
    final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);
    The code for stored procedure solution:
    final JpaCallback action = new JpaCallback() {
      @Override
      public Object doInJpa(final EntityManager em) throws PersistenceException {
          final Session session = JpaHelper.getEntityManager(em).getActiveSession();
           * Using CallableStatement for stored procedure
          STRUCT st = null;
          CallableStatement cs = null;
          final DatabaseLogin login = session.getLogin();
          final Connection _conn = (Connection) login.connectToDatasource(session.getDatasourceLogin().buildAccessor(), session);
          try {
             try {
                cs = _conn.prepareCall("{call GET_GEO_BRD_PROCEDURE(?,?)}");
                cs.setString("p_geo_brd_id", "2e531e62-2105-4522-978a-ab8baf19e273");
                cs.registerOutParameter("sdo_geom", OracleTypes.STRUCT, "MDSYS.SDO_GEOMETRY");
                cs.execute();
              } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured calling the stored procedure", e);
              if (cs != null) {
                //reading geometry from the database
                try {
                   st = (STRUCT) cs.getObject("sdo_geom");
                } catch (final SQLException e) {
                   MyClass.LOG.error("An exception occured converting the query result to oracle.sql.STRUCT", e);
           } finally {
              try {
                if (_conn != null && !_conn.isClosed()) {
                   _conn.close();
              } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured on closing the database connection.", e);
            return st;
    final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);

  • How to Call Stored Proc. through JDBC from SQL Server

    I have to call Stored Procedure by JDBC in java. This is the prog i m using:
    import java.sql.*;
    import java.io.*;
    class callSP
    public static void main(String a[]) throws Exception
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c=DriverManager.getConnection("jdbc:odbc:first","sa","");
    //CallableStatement cs=c.prepareCall("{? =call GET_CLUSTER(?)}");
    CallableStatement cs=c.prepareCall("{call GET_CLUSTER(?)}");
    cs.registerOutParameter(1,Types.CHAR);
    //cs.setString(1, "Teamwork");
    cs.execute();
    //cs.executeUpdate();
    String output=cs.getString(1);
    System.out.println(output);
    catch (SQLException e)
    System.out.println(e);
    This is the Stored Procedure:
    CREATE PROCEDURE GET_CLUSTER
    @Ip_THESAURUS_KEY_WORD CHAR(40)
    AS
    DECLARE @Lc_THESAURUS_CODE INT,
    @Lc_CLUSTER_CODE INT
    BEGIN
    --GET THE THESARUS CODE FOR THE KEYWORD
    SELECT @Lc_THESAURUS_CODE = THESAURUS_CODE
    FROM THESAURUS_LIST
    WHERE THESAURUS_KEY_WORD = @Ip_THESAURUS_KEY_WORD
    --GETTING THE CLUSTER ID
    SELECT @Lc_CLUSTER_CODE = CLUSTER_CODE
    FROM THESAURUS_ENRICH_CLUSTER
    WHERE THESAURUS_CODE = @Lc_THESAURUS_CODE
    --GET THE CLUSTER KEYWORDS
    SELECT THESAURUS_KEY_WORD
    FROM THESAURUS_LIST T,THESAURUS_ENRICH_CLUSTER C
    WHERE T.THESAURUS_CODE=C.THESAURUS_CODE
    AND C.CLUSTER_CODE=@Lc_CLUSTER_CODE AND NOT THESAURUS_KEY_WORD=@Ip_THESAURUS_KEY_WORD
    END
    GO
    Check it out what is problem. Data is not getting, it is giving exception.

    Please be specific regarding the problem that you are facing, that's the key to getting help in the forum. If there's exception in your program, such as NullPointerException or SQLException, please state it in your post.

  • How to call stored procedures from java program?

    I have tried to run a program that calls a stored procedure on MySQL
    server version 5.0.17 by using connector/j 5.0, but it always fails on the
    statement: con.preparecall() ,
    have looked on the internet and found out that people can all mysql
    stored procedure all right in their programs, really dont know what's
    wrong with this small peiece of code:
    import java.sql.*;
    public class TestDB {
          // procedure being called is:
         CREATE PROCEDURE `dbsaystorm`.`getsite` ()
         BEGIN
            select  name  from tblsite;
         END
         public static void main(String[] args) {
              try  {
                  //Class.forName("org.gjt.mm.mysql.Driver");
                  Class.forName("com.mysql.jdbc.Driver");
                  Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbname",
                            "user", "pwd");
           * executing SQL statement here gives perfect correct results:
            // PreparedStatement ps = con.prepareStatement("select name from tblsite");      
            // ResultSet rs =ps.executeQuery();
                  // but in stored procedure way...
                  //it fails here on this prepare call statement:             
                  CallableStatement proc = con.prepareCall("call getsite()");
                  ResultSet rs =proc.executeQuery();                      
                  if (rs == null) return;                                      
                  while (rs.next()){                 
                      System.out.println("site name is: "+ rs.getString(1));                                
                  rs.close();
              } catch (SQLException e) {e.printStackTrace();}
               catch (Exception e) {e.printStackTrace();}         
    }it always gives this exception:
    java.lang.NullPointerException
         at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:959)
         at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1280)
         at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3668)
         at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:638)
         at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:453)
         at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4365)
         at com.mysql.jdbc.Connection.prepareCall(Connection.java:4439)
         at com.mysql.jdbc.Connection.prepareCall(Connection.java:4413)
         at saystorm.server.data.database.TestDB.main(TestDB.java:29)
    where have I gone wrong?
    when I commented out the statement that makes the procedure call and call preparedstatement to execute SQL select statement, it gave perfectly correct result.
    it looks like there is no problem with java prog accessing MYSQL server database, but the it seems that it's just java can't call stored procedure stored on the mysql server version 5.
    can it or can't it? if it can, how is that accomplished?

    It is a bug in the driver because it shouldn't be
    returning that exception (null pointer) even if you
    are doing something wrong.
    Are you using the latest version of the driver?
    The stored procedure runs when you run it from the
    gui/command line using a MySQL tool - correct?
    As suggested you should be using the brackets. What
    is the data type of the 'name' field?
    You could try returning another value like one of the
    following
    select 1, name from tblsite;
    select name, 1 from tblsite;
    That might get around the bug
    Additionally try just the following...
    select 'test' from tblsite;yes, the driver used is in connector/j 5.0--the lastest one, and the
    procedure can run correctedly at either command line or GUI mode
    with no problem whatsoever, the returned data type is string type,
    I have not got the chance to test it again with those values you
    suggested, as I have abandoned the laptop I used to write that code
    initately. There have been some other really weird cases happened on
    that computer. I guess that must be something wrong with the JVM
    installed on it, it was upgraded from jre5.0.04 to 06, and to 09.
    something within hte JVM must have been messed up(the only reasonable
    explanation). Because the same code runs correctly on my new laptop,
    using the same environment: jvm 5.0_09, mysql 5.0.18, connector/J 5.0.
    that old laptop really was a nightmare.

  • To call db2 stored procedure having parameters in java application

    Hi,
    I've created db2 stored procedure which is running perfectly on db2 server after giving a CALL to it. But when I tried to call this same stored procedure in java application, its reflecting with following error......
    com.ibm.db2.jcc.b.SqlException: [jcc][10100][10910][3.50.152] java.sql.CallableStatement.executeQuery() was called but no result set was returned.
    Use java.sql.CallableStatement.executeUpdate() for non-queries. ERRORCODE=-4476, SQLSTATE=null
    at com.ibm.db2.jcc.b.wc.a(wc.java:55)
    at com.ibm.db2.jcc.b.wc.a(wc.java:102)
    at com.ibm.db2.jcc.b.tk.b(tk.java:575)
    at com.ibm.db2.jcc.b.vk.yb(vk.java:136)
    at com.ibm.db2.jcc.b.vk.executeQuery(vk.java:114)
    at SPApplication.main(SPApplication.java:31)
    Here is the code.......
    import java.sql.*; public class SPApplication { public static Connection con; public static CallableStatement proc_stmt; public static ResultSet rs; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { Class.forName("DB2 DRIVER CLASS"); System.out.println("Class loaded....."); con = DriverManager.getConnection("jdbc:db2://localhost:PORTNO/" +                                   " DatabaseName", "username", "password"); System.out.println("Connection established....."); proc_stmt = con.prepareCall("call procedure_name(?)"); //IN Parameter proc_stmt.setInt(1, 5); System.out.println("Called procedure....."); rs = proc_stmt.executeQuery(); /******** THIS IS LINE NO. 31 *********/ while (rs.next()) {                              // Fetching rows one by one over here } proc_stmt.close(); rs.close(); con.close(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } finally { /* try { proc_stmt.close(); rs.close(); con.close(); } catch (SQLException sqle) { sqle.printStackTrace(); } */ } } }
    Please correct me, if I am wrong at any point in my application..
    I would really appreciate for resolving my problem.
    Thanks,
    Manasi N.

    Hi jschell ,
    Firstly, I tried out with execute() and getMoreResults() to check if the statement is returning result set. - Its returning "null" only.
    Secondly, I tried with following one by one :
    1. Find a new jdbc driver
    2. Write a different stored procedure.I am using DB2 Express edition - DB2 v9.7.0.0
    I have the required jar files - i)db2jcc.jar ii) db2jcc_license_cu.jar
    From these I found the available jdbc drivers as -
    i) com.ibm.db2.jcc.DB2Driver
    ii) COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver
    iii) com.ibm.db2.jcc.uw.DB2StoredProcDriver
    I tried out my code by using each of these drivers, but still returning result set as null.
    Moreover, I changed my stored procedure which has cursor returning result set. In this case also, result set is null.
    Code snippet for this SP is -
    30             Class.forName("com.ibm.db2.jcc.uw.DB2StoredProcDriver");
    31             System.out.println("Class loaded....");
    32             con = DriverManager.getConnection
    33                 ("jdbc:db2://localhost:portno/dbName", "user", "password");
    34             System.out.println("Connection established....");
    35
    36             proc_stmt = con.prepareCall("call javaSP()");
    37            
    38             System.out.println("Called stored procedure....");
    39            
    40             proc_stmt.execute();
    41             //proc_stmt.executeUpdate();
    42             //rs = proc_stmt.getResultSet();
    43
    44             System.out.println("Query executed....");
    45            
    46             if ((proc_stmt.getMoreResults() == false) &&
    47                     (proc_stmt.getUpdateCount() == -1)) {
    48                 System.out.println("No more result sets");
    49             }o/p is (for every mentioned above jdbc driver) :-
    Class loaded....
    Connection established....
    Called stored procedure....
    Query executed....
    No more result sets..
    The o/p is always "No more result sets"
    What else can be tried out to retrieve the result set from stored procedure from Java application? And the most important, these same stored procedures are returning result sets on db2 server after calling them.
    Thank you,
    Manasi.N
    Edited by: Manasi.N on Apr 14, 2010 12:27 AM
    Edited by: Manasi.N on Apr 14, 2010 12:28 AM

  • How to use @jws:sql call Stored Procedure from Workshop

    Is there anyone know how to use @jws tag call Sybase stored procedure within
    Workshop,
    Thanks,

    Anurag,
    Do you know is there any plan to add this feature in future release? and
    when?
    Thanks,
    David
    "Anurag Pareek" <[email protected]> wrote in message
    news:[email protected]..
    David,
    In the current release, we do not support calling stored procedures from a
    database control. You will have to write JDBC code in the JWS file to call
    stored procedures.
    Regards,
    Anurag
    Workshop Support
    "David Yuan" <[email protected]> wrote in message
    news:[email protected]..
    Anurag,
    I know how to use DB connection pool and create a db control with it. In
    fact, we have created a Web Service with the db control using plain SQL
    in
    @jws:sql. However, my question here is how to use @jws tag in Weblogic
    Workshop to create a Web Services based on Sybase stored procedure orany
    Stored Proc not plain SQL.
    Thanks,
    David
    "Anurag Pareek" <[email protected]> wrote in message
    news:[email protected]..
    David,
    You can use a database control to obtain a connection from any JDBC
    Connection Pool configured in the config.xml file. The JDBC Connectionpool
    could be connecting to any database, the database control is
    independent
    of
    that.
    Regards,
    Anurag
    Workshop Support
    "David Yuan" <[email protected]> wrote in message
    news:[email protected]..
    Is there anyone know how to use @jws tag call Sybase stored
    procedure
    within
    Workshop,
    Thanks,

  • Calling Stored Procedure(takes varray of objects as input) from jdeveloper

    How can i call Stored Procedure which takes varray of objects as input from jdeveloper
    My object is :
    TYPE Entry IS Object (
    Name VARCHAR2(1024),
    Value VARCHAR2(1024)
    & the varray is :
    TYPE EntryArr IS varray(10) OF Entry ;
    & the procedure is :
    PROCEDURE myProc( myEntryArr IN EntryArr )
    AS
    s varchar2(1024);
    BEGIN
    for i in 1.. myEntryArr .COUNT loop
    if myEntryArr(i).Name = 'Name1' then
    s := myEntryArr(i).Value
    end loop;
    end;

    hi 429071
    Maybe you can find some useful information in:
    "Oracle Database Java Developer's Guide"
    http://download-west.oracle.com/docs/cd/B14117_01/java.101/b12021.pdf
    see "6 Publishing Java Classes With Call Specs" > "Writing Object Type Call Specs"
    success
    Jan Vervecken

  • Calling Stored Procedure from Oracle DataBase using Sender JDBC (JDBC-JMS)

    Hi All,
    We have requirement to move the data from Database to Queue (Interface Flow: JDBC -> JMS).
    Database is Oracle.
    *Based on Event, data will be triggered into two tables: XX & YY. This event occurs twice daily.
    Take one field: 'aa' in XX and compare it with the field: 'pp' in YY.
    If both are equal, then
         if the field: 'qq' in YY table equals to "Add" then take the data from the view table: 'Add_View'.
         else  if the field: 'qq' in YY table equals to "Modify"  then take the data from the view table: 'Modify_View'.
    Finally, We need to archive the selected data from the respective view table.*
    From each table, data will come differently, means with different field names.
    I thought of call Stored Procedure from Sender JDBC Adapter for the above requirement.
    But I heard that, we cannot call stored procedure in Oracle through Sender JDBC as it returns Cursor instead of ResultSet.
    Is there any way other than Stored Procedure?
    How to handle Data Types as data is coming from two different tables?
    Can we create one data type for two tables?
    Is BPM required for this to collect data from two different tables?
    Can somebody guide me on how to handle this?
    Waiting eagerly for help which will be rewarded.
    Thanks and Regards,
    Jyothirmayi.

    Hi Gopal,
    Thank you for your reply.
    >Is there any way other than Stored Procedure?
    Can you try configuring sender adapter to poll the data in intervals. You can configure Automatic TIme planning (ATP) in the sender jdbc channel.
    I need to select the data from different tables based on some conditions. Let me simplify that.
    Suppose Table1 contains 'n' no of rows. For each row, I need to test two conditions where only one condition will be satisfied. If 1st condition is satisfied, then data needs to be taken from Table2 else data needs to be taken from Table3.
    How can we meet this by configuring sender adapter with ATP?
    ================================================================================================
    >How to handle Data Types as data is coming from two different tables?
    If you use join query in the select statement field of the channel then whatever you need select fields will be returned. This might be fields of two tables. your datatype fields are combination of two diff table.
    we need to take data only from one table at a time. It is not join of two tables.
    ================================================================================================
    Thanks,
    Jyothirmayi.

Maybe you are looking for

  • Account Under Contstruction relationship with GL account

    Hi Friends, I am not from FI so i want to know basics of AUC account. 1. What is the relationship between AUC account and Gl account? 2. Under which account type AUC comes? 3. Do AUC account is maintained under different document type like AA, AB, SP

  • How do I get a contact's name/photo to appear when they call/text (rather than their number)?

    I have one contact with whom I communicate regularly and their photo image appears whenever they call or text me. I don't know what I did to make that happen, and I cannot get it to happen for the other people in my Contact List. Can anyone tell me h

  • The Dreaded 'Disk Wasn't Ejected Properly' Error Message

    Hi, brand new machine - hooked up an external USB 3 drive and switched Time Machine on. When the computer sleeps, it awakes to 'Disk Wasn't Ejected Properly' error message. Apple Support weren't much support, they had NO fix. Any ideas?

  • JMS and JDBC Adapter in PI7.1

    Hi All, Kindly tell me about the blogs for JMS and JDBC adapter. Please tell me about the Message Types in JMS adapter. Thanks in advance.

  • Multitouch support for trackpad on Windows

    Is there any way to enable full multitouch support for the Macbook Pro trackpad under Windows? The two-finger scrolling works perfectly but I miss the three finger swipe and thre-finger flick whenever I boot on Windows.