?
Solved

JDBC Trying to get value?

Posted on 2001-06-29
3
Medium Priority
?
365 Views
Last Modified: 2012-06-27
I have an Oracle stored function that I want to get a value from.  I run the following java code and get error.

           long _lID = 0;
           
            if(( _gstmt instanceof CallableStatement ) == false )
                _gstmt = _DBConnect.prepareCall("{? = call spLogin[(?,?)]}");
           
            _gstmt.registerOutParameter(1, java.sql.Types.NUMERIC );
            _gstmt.setString(2, strUserID );
            _gstmt.setString(3, strPassword );
            _gstmt.execute();
           
            _lID = _gstmt.getLong(1);

Here is my stord function:

CREATE OR REPLACE FUNCTION spLogin (varUserID IN VARCHAR2,varPassword IN VARCHAR2)
 RETURN NUMBER AS

 CURSOR cur_emp IS
   SELECT CompanyEmployeeID
   FROM CompanyEmployees_Syn
   WHERE UserID = varUserID
   AND UserPassword = varPassword;

       nEmployeeID NUMBER DEFAULT 0;

BEGIN
 OPEN cur_emp ;
 FETCH cur_emp INTO nEmployeeID ;
 DBMS_OUTPUT.PUT_LINE( nEmployeeID );
 CLOSE cur_emp ;
 RETURN nEmployeeID;

 EXCEPTION
  WHEN OTHERS THEN
  RETURN -1;
END;

Error I get:

java.sql.SQLException: ORA-06550: line 1, column 20:
PLS-00103: Encountered the symbol "[" when expecting one of the following:
 
   . ( * @ % & = - + ; < / > at in mod not rem
   <an exponent (**)> <> or != or ~= >= <= <> and or like
   between is null is not || is dangling
The symbol "[" was ignored.
ORA-06550: line 1, column 28:
PLS-00103: Encountered the symbol "]" when expecting one of the following:
 
   . ( * % & = - + ; < / > at in mod not rem <an exponent (**)>
   <> or != or ~= >= <= <> and or like between is null is not ||
   is dangling
The symbol "]" was
 
java.sql.SQLException: ORA-06550: line 1, column 20:
PLS-00103: Encountered the symbol "[" when expecting one of the following:
 
   . ( * @ % & = - + ; < / > at in mod not rem
   <an exponent (**)> <> or != or ~= >= <= <> and or like
   between is null is not || is dangling
The symbol "[" was ignored.
ORA-06550: line 1, column 28:
PLS-00103: Encountered the symbol "]" when expecting one of the following:
 
   . ( * % & = - + ; < / > at in mod not rem <an exponent (**)>
   <> or != or ~= >= <= <> and or like between is null is not ||
   is dangling
The symbol "]" was
 
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
        at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
        at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
        at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
        at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:822)
        at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1446)
        at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1371)
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1900)
        at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:363)
        at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:407)
        at Login.ValidateUser(Login.java:183)
        at Login.btnOKActionPerformed(Login.java:130)
        at Login.access$1(Login.java:110)
        at Login$2.actionPerformed(Login.java:53)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
        at java.awt.Component.processMouseEvent(Component.java:3715)
        at java.awt.Component.processEvent(Component.java:3544)
        at java.awt.Container.processEvent(Container.java:1164)
        at java.awt.Component.dispatchEventImpl(Component.java:2593)
        at java.awt.Container.dispatchEventImpl(Container.java:1213)
        at java.awt.Component.dispatchEvent(Component.java:2497)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
        at java.awt.Container.dispatchEventImpl(Container.java:1200)
        at java.awt.Window.dispatchEventImpl(Window.java:914)
        at java.awt.Component.dispatchEvent(Component.java:2497)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
0
Comment
Question by:borg48
  • 2
3 Comments
 

Author Comment

by:borg48
ID: 6240045
Figured out the problem but not gettting result id back:

I took out the [] in the code:

           if(( _gstmt instanceof CallableStatement ) == false )
                _gstmt = _DBConnect.prepareCall("{? = call spLogin(?,?)}");
           
            _gstmt.registerOutParameter(1, java.sql.Types.NUMERIC );
            _gstmt.setString(2, strUserID );
            _gstmt.setString(3, strPassword );
            _gstmt.execute();
           
            _lID = _gstmt.getLong(1);

I'm just not getting the _lID value?

No errors at all
0
 
LVL 6

Accepted Solution

by:
jpk041897 earned 200 total points
ID: 6241882
The java.sql.Types.NUMERIC maps to either a java.math.BigDecimal or a oracle.sql.NUMBER

so you would need to change the line that reads:

 _lID = _gstmt.getLong(1);

to:

 _lID = _gstmt.getBigDecimal(1);

and change the _IID declaration accordingly.

Hope this helps.
0
 

Author Comment

by:borg48
ID: 6251639
Thanks allot for the info.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question