Solved

JDBC Trying to get value?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

830 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