Solved

JDBC Trying to get value?

Posted on 2001-06-29
3
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss wildfly 10.1 10 597
mysql jsp example issue 32 96
Glassfish admin console not working 1 87
learn programming 8 94
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
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.
Suggested Courses

737 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