Solved

JDBC Trying to get value?

Posted on 2001-06-29
3
338 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks allot for the info.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now