Solved

JDBC Trying to get value?

Posted on 2001-06-29
3
341 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 50 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

786 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