Enterprise Java Bean and SQL : SQLException 
Author Message
 Enterprise Java Bean and SQL : SQLException

Hi,

I'm testing out a simple session to query a DB2 database.  When I use
the following piece of code, the bean executes fine:

public String getStudentList() throws java.rmi.RemoteException {
   //query database to get list students
   String query = "select * from oslevel.t_samplestudennt";
   try {
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(query);
      if (rs.next()) {
      // return just one first name
         String studentFName = rs.getString(3);
         return studentFName;
      }
      else
         return null;
   }
   catch (SQLException e){
      return "exception";
   }

Quote:
} // end

however, if I change the select statement from above to select just one
field, for example:
   "select oslevel.t_samplestudent.studentID from
oslevel.t_samplestudent"

it raises a SQLException.  Does anyone know what I'm doing wrong?
Thanks for any help.

TNguyen

Sent via Deja.com http://www.***.com/
Share what you know. Learn what you don't.



Mon, 17 Dec 2001 03:00:00 GMT
 Enterprise Java Bean and SQL : SQLException

Quote:

> I'm testing out a simple session to query a DB2 database.  When I use
> the following piece of code, the bean executes fine:

> public String getStudentList() throws java.rmi.RemoteException {
>    //query database to get list students
>    String query = "select * from oslevel.t_samplestudennt";
>    try {
>       Statement stmt = con.createStatement();
>       ResultSet rs = stmt.executeQuery(query);
>       if (rs.next()) {
>       // return just one first name
>          String studentFName = rs.getString(3);
>          return studentFName;
>       }
>       else
>          return null;
>    }
>    catch (SQLException e){
>       return "exception";
>    }
> } // end

> however, if I change the select statement from above to select just one
> field, for example:
>    "select oslevel.t_samplestudent.studentID from
> oslevel.t_samplestudent"

> it raises a SQLException.  Does anyone know what I'm doing wrong?
> Thanks for any help.

You didn't show the details from the exception, but if you didn't change the line:

          String studentFName = rs.getString(3);

you'll get an exception for referencing the 3rd result column of a single column result
set.

--
Lee Fe{*filter*}an, FFE Software, Inc. ( http://www.***.com/ )



Mon, 17 Dec 2001 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. SQLException: java.sql.SQLException: No suitable driver

2. Enterprise Java Bean

3. Oracle Application Server and Enterprise Java Beans.

4. Problems installing Enterprise Java Beans in Oracle Application Server 4

5. Oracle Application Server and Enterprise Java Beans.

6. Problems installing Enterprise Java Beans in Oracle Application Server 4

7. java.sql.SQLException: java.lang.NumberFormatException with WorkBook

8. EJB, Java Beans, WebSphere, Weblogic, C++/CORBA, Java/CORBA.-F/T and Contract

9. EJB, Java Beans, WebSphere, Weblogic, C++/CORBA, Java/CORBA.-F/T

10. VA-Chantilly-242095--Java-JavaBeans-CORBA-ORACLE-Telecommunications-WEB DEVELOPER

11. VA-Chantilly-242095--Java-JavaBeans-CORBA-ORACLE-Telecommunications-WEB DEVELOPER


 
Powered by phpBB® Forum Software