enterprise javabean and SQL: SQLException 
Author Message
 enterprise javabean and SQL: SQLException

Hi,

I'm testing out a simple session bean in VisualAge 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 javabean and SQL: SQLException

Assuming studentID is a var(char) column, are you changing
rs.getString(3) to rs.getString(1) when using the new
SQL statement?

-- Damodar Periwal
   Software Tree, Inc.
   http://www.softwaretree.com

Quote:

> Hi,

> I'm testing out a simple session bean in VisualAge 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.

> TNguyen

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



Fri, 21 Dec 2001 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. Enterprise Java Bean and SQL : SQLException

2. FS: "Enterprise JavaBeans"

3. Enterprise JavaBeans

4. Enterprise Javabeans and/or CORBA Transaction Services

5. Looking for the job;Enterprise JavaBeans Developer

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

7. MO-ST LOUIS-99224--DB2-Java-JavaBeans-ORACLE-PL/SQL-Java P/A

8. VA-Herndon-241328--Software Development-Java-LDAP-SQL-PL/SQL-ORACLE-JavaBeans-Software Developer

9. NJ-Bridgewater-260560--SQL-JDBC-ORACLE-JavaBeans-UML-HTML-Java Developer

10. java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Optional feature not implemented

11. java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Timeout expired


 
Powered by phpBB® Forum Software