ResultSet.next() throws NullPointerException

Hello,
When running the following code:
import java.sql.*;
class DatabaseDriver {
     private int                    databaseType;
     private String               error;
     private Connection     con;
     private Statement          statement;
     private ResultSet          rs;
     static final int          MYSQL_DB_TYPE = 1;
     static final int          PGSQL_DB_TYPE = 2;
     static final int          MSSQL_DB_TYPE = 3;
     static final int          ORACLE_DB_TYPE = 4;
     public DatabaseDriver (int dbType) {
          databaseType = dbType;
          try {
               switch (dbType) {
                    case MYSQL_DB_TYPE:
                         Class.forName("com.mysql.jdbc.Driver").newInstance();
                         break;
                    case PGSQL_DB_TYPE:
                         Class.forName("org.postgresql.Driver").newInstance();
                         break;
                    case MSSQL_DB_TYPE:
                         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
                         break;
                    case ORACLE_DB_TYPE:
                         Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                         break;
          } catch (Exception e) {
               error = "could not load driver";
     public boolean connect (String server, String user, String password) {
          try {
               con = DriverManager.getConnection("jdbc:mysql://" + server + "?user=" + user + "&password=" + password);
          } catch (Exception e) {
               error = "could not connect to the database";
               return false;
          return true;
     public boolean execQuery (String query) {
          try {
               statement = con.createStatement();
               if (statement.execute(query)) {
                    rs = statement.getResultSet();
               while (rs.next()) {
                    System.out.println(rs.getString("1") + "\t" + rs.getString("2"));
               rs.close();
               rs = null;
               statement.close();
               statement = null;
          } catch (Exception e) {
               error = e.toString();
               e.printStackTrace();
               return false;
          return true;
     public String getError () {
          return error;
     public boolean disconnect () {
          return true;
class Test {
     public static void main (String[] args) {
          DatabaseDriver db = new DatabaseDriver(1);
          db.connect(args[0],args[1],args[2]);
          db.execQuery("USE " + args[3] + ";");
          db.execQuery("SELECT * FROM te;");
          System.out.println(db.getError());
}I receive this in the printout:
java.lang.NullPointerException
     at DatabaseDriver.execQuery(DatabaseDriver.java:61)
     at Test.main(Test.java:7)
bla1     bla2
bla6     bla7
java.lang.NullPointerException
Line 61
while (rs.next()) {
I have read a lot of other posts that say that the connection object is null or the recordset is empty, but it seems that neither of those are the case considering I am able to printout the two rows properly.
Can someone please explain to me what I am doing wrong and how to fix it?
Thanks

You can pepper your code with System.out.println() statements to determine what value goes into the execute() statement before it runs.
In the following, I think the first statement will probably return false. What is this sql trying to accomplish that you think it sould return true? Even if it returned true, what value do you expect in the resultSet?
db.execQuery("USE " + args[3] + ";");
db.execQuery("SELECT * FROM te;");
As a side note, I strongly suggest you use connection pooling and not driverManager. here is an example of getting and returning a connection properly (all within a function)
public String[] myFunction(){
Connection conn=null;
PreparedStatement pstmt1= null;
ResultSet resultSet=null;
ArrayList list1; //array that can grow in size
try{
list1=new ArrayList();
conn= dataSource.getConnection();
pstmt1= conn.prepareStatement();
resultSet= pstmt1.executeUpdate();
while(resultSet.next()){
arrayList.add(resultSet.getString("lastName");
return ( String[] ) arrayList.toArray( new String[arrayList.size()] );
} catch (SqlException e){
e.printStackTrace();
} finally {
if(rsultSet!=null)
resultSet.close();
if(pstmt1!=null)
pstmt1.close();
if(conn!=null)
conn.close();
}

Similar Messages

  • ResultSet.next() throws exception

    I am working on a BEA Weblogic application migration from 7.1 to 8.1. My application has lots of Oracle user defined package functions for providing database query. Those functions return a cursor pointing to the query results (ResultSet object in JDBC). My BEA Weblogic 8.1 java application, which invokes those Oracle functions, uses getObject() method to get query ResultSet. Follows are a java code snippet and exception thrown when using ResultSet.next() method to move cursor. Thanks.
    =================== code snippet ========================
    CallableStatement cs1 = (CallableStatement)conn.prepareCall("{? = call pkg_profile.fn_get_user_data(?) }");
    cs1.registerOutParameter(1, java.sql.Types.OTHER);
    cs1.setString (2, c_strUsername);
    cs1.execute();
    // Get the Result
    ResultSet rs1 = (ResultSet)cs1.getObject(1);
    if (rs1 == null || !rs1.next()) { <=== exception thrown due to moving cursor to the next row of query result.
    =================== code snippet =======================
    Exception -
    ERROR 24 Nov 2004 12:19:28,527 USER:supuser - CNTXT:MISUserProfile.userDataDispatcher | SQL Error while retrieving data for user. | java.sql.SQLException: java.lang.NullPointerException: CDA is null
    Start server side stack trace:
    java.lang.NullPointerException: CDA is null
    at weblogic.db.oci.OciCursor.arrayFetch(Native Method)
    at weblogic.db.oci.OciCursor.oci_arrayFetch(OciCursor.java:2338)
    at weblogic.jdbc.oci.ResultSet.next(ResultSet.java:774)
    at weblogic.jdbc.rmi.internal.ResultSetImpl.next(ResultSetImpl.java:135)
    at weblogic.jdbc.rmi.internal.ResultSetImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:821)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
    End server side stack trace

    Try this one...
    Before excecuting the query setAutoCommit false and then try to execute the query.After executing query manually do commit.It should work.

  • UpdatableResultSet.next throws NullPointerException

    Execute a query and then loop through the result set doing
    rs.getString(1) over and over.
    Keep getting the following exception:
    java.lang.NullPointerException
    at oracle.jdbc.driver.UpdatableResultSet.next
    (UpdatableResultSet.java, Compiled Code)
    Anyone else seen this?

    You can pepper your code with System.out.println() statements to determine what value goes into the execute() statement before it runs.
    In the following, I think the first statement will probably return false. What is this sql trying to accomplish that you think it sould return true? Even if it returned true, what value do you expect in the resultSet?
    db.execQuery("USE " + args[3] + ";");
    db.execQuery("SELECT * FROM te;");
    As a side note, I strongly suggest you use connection pooling and not driverManager. here is an example of getting and returning a connection properly (all within a function)
    public String[] myFunction(){
    Connection conn=null;
    PreparedStatement pstmt1= null;
    ResultSet resultSet=null;
    ArrayList list1; //array that can grow in size
    try{
    list1=new ArrayList();
    conn= dataSource.getConnection();
    pstmt1= conn.prepareStatement();
    resultSet= pstmt1.executeUpdate();
    while(resultSet.next()){
    arrayList.add(resultSet.getString("lastName");
    return ( String[] ) arrayList.toArray( new String[arrayList.size()] );
    } catch (SqlException e){
    e.printStackTrace();
    } finally {
    if(rsultSet!=null)
    resultSet.close();
    if(pstmt1!=null)
    pstmt1.close();
    if(conn!=null)
    conn.close();
    }

  • ResultSet.next() and resultset.islast() problem

    I have query which returns 10 records. I run the using preparedStatement. When i use the while(resultSet.next()), the loop runs untill 10 records and after that when it come to the while check it hangs.
    Sample code
    pstmt= conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    rs = pstmt.executeQuery();
    while (rsAccessNoEq.next()) {...
    Then i added the code in the while loop
    if(rs.isLast()){
    return;
    For the first iteration itself the theisLast() is true and it terminates from the loop.
    Please help me

    public class ISP {
         private GFA gestorFic = null;
         private GCA gestorCad = null;
         private GBDAgestor = null;
         private String path = null;
         ServiceProcessVO javaIntra = null;
         ServiceProcessVO javaIntra1 = null;
         ServiceProcessVO javaIntra2 = null;
         ServiceProcessVO javaIntra3 = null;
         ArrayList dataList = null;
         List dataFile = null;
         ArrayList dataList1 = null;
         ArrayList dataList2 = null;
         ArrayList dataList3 = null;          
         public final void iP() throws SQLException,
         MCEA {
         ResultSet rsIntraHq = null;
              Connection connIntraHq = null;
              PreparedStatement pstmtIntraHq = null;
              ResultSet rsIntraFlow = null;
              Connection connIntraFlow = null;
              PreparedStatement pstmtIntraFlow = null;
              ResultSet rsEqNoAccess = null;
              Connection connEqNoAccess = null;
              PreparedStatement pstmtEqNoAccess = null;
              ResultSet rsAccessNoEq = null;
              Connection connAccessNoEq = null;
              PreparedStatement pstmtAccessNoEq = null;
              ResultSet rsFlowHqAccess = null;
              Connection connFlowHqAccess = null;
              PreparedStatement pstmtFlowHqAccess = null;
              dataList = new ArrayList();          
              dataFile = new ArrayList();
              System.out.println("At the begining :"+now() );
              dataFile = gestorFic.leerArchivo(path, file);
              System.out.println("After first step :"+now() );
              int size1 = dataFile.size();
              try {
                   connAccessNoEq = gestor.getConnection();
                   javaIntra = new ServiceProcessVO();
                   pstmtAccessNoEq = connAccessNoEq
                   .prepareStatement(ConsultasAssets.INTRA_ACCESS_NOEQ);
                             //ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                   pstmtAccessNoEq.setString(1, oti);
                   pstmtAccessNoEq.setString(2, oti);
                   pstmtAccessNoEq.setString(3, oti);
                   rsAccessNoEq = pstmtAccessNoEq.executeQuery();
                   //int k = rsAccessNoEq.TYPE_SCROLL_SENSITIVE;
                   int i = 0;
                   //rsAccessNoEq.last();
                   while (rsAccessNoEq.next()) {
                        i++; System.out.println("Begin of loop:"+i);
                        javaIntra = populatedata(rsAccessNoEq, true);
                        dataList.add(javaIntra);
                        // Flow Hq Access
                        try {
                             connFlowHqAccess = gestor.getConnection();
                             javaIntra1 = new ServiceProcessVO();
                             pstmtFlowHqAccess = connFlowHqAccess
                             .prepareStatement(ConsultasAssets.HQ_ACCESS);
                             pstmtFlowHqAccess.setString(1, javaIntra
                                       .getCTASOCIACION().trim());
                             pstmtFlowHqAccess.setString(2, rsAccessNoEq.getString(1)
                                       .trim());
                             pstmtFlowHqAccess.setString(3, rsAccessNoEq.getString(3)
                                       .trim());
                             pstmtFlowHqAccess.setString(4,oti);
                             pstmtFlowHqAccess.setString(5,oti);
                             pstmtFlowHqAccess.setString(6,oti);
                             rsFlowHqAccess = pstmtFlowHqAccess.executeQuery();
                             while (rsFlowHqAccess.next()) {
                                  javaIntra1 = populatedata(rsFlowHqAccess, false);
                                  dataList.add(javaIntra1);
    //                         if(rsAccessNoEq.isAfterLast()){
    //                              return;
                        } catch (SQLException se) {
                             MCLA.logFatel(ClassNameAssets
                                       .getQualifiedClassName()
                                       + ": "
                                       + ClassNameAssets.getLineNumber()
                                       + ": "
                                       + "Error Occurred in HQ_ACCESS: "
                                       + se.getMessage());
                             throw new MigracionCommonExceptionAssets(se.getMessage());
                        } finally {
                             pstmtFlowHqAccess.close();
                             if (rsFlowHqAccess != null) {
                                  rsFlowHqAccess.close();
                             //gestor.releaseConn(connFlowHqAccess);
         private SPVOpopulatedata(ResultSet rsCpProcess, boolean modify)
         throws SQLException {
              SPVOjavaIntra = new ServiceProcessVO();
              if (rsCpProcess.getString(ConstantesAssets.NU) != null
                        && !rsCpProcess.getString(ConstantesAssets.NU)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setNU(rsCpProcess.getString(
                             ConstantesAssets.NU).trim());
              if (rsCpProcess.getString(ConstantesAssets.NU_ASO) != null
                        && !rsCpProcess.getString(ConstantesAssets.NU_ASO)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setNU_ASO(rsCpProcess.getString(
                             ConstantesAssets.NU_ASO).trim());
              // HashTable logic to increament value for CTASOCIACION Start
              if (modify == true) {
                   if (rsCpProcess.getString(ConstantesAssets.CTASOC) != null
                             && !rsCpProcess.getString(ConstantesAssets.CTASOC)
                             .equalsIgnoreCase(ConstantesAssets.BLANK)) {
                        char cha = ConstantesAssets.A;
                        if (tempMap.get(javaIntra.getNU()) != null) {
                             cha = tempMap.get(javaIntra.getNU()).toString()
                             .charAt(0);
                             cha++;
                        tempMap.put(javaIntra.getNU(), Character
                                  .toString(cha));
                        javaIntra.setCTASOCIACION(((rsCpProcess
                                  .getString(ConstantesAssets.CTASOC).trim()) + cha)
                                  .trim());
              } else {
                   javaIntra.setCTASOCIACION(rsCpProcess.getString(
                             ConstantesAssets.CTASOC).trim());
              // HashTable logic to increament value for CTASOCIACION End
              if (rsCpProcess.getString(ConstantesAssets.CCC) != null
                        && !rsCpProcess.getString(ConstantesAssets.CCC)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setCCC(rsCpProcess.getString(
                             ConstantesAssets.CCC).trim());
              if (rsCpProcess.getString(ConstantesAssets.FIV1) != null
                        && !rsCpProcess.getString(ConstantesAssets.FIV1)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setFIV(rsCpProcess.getString(
                             ConstantesAssets.FIV1).trim());
              if (rsCpProcess.getString(ConstantesAssets.FFV) != null
                        && !rsCpProcess.getString(ConstantesAssets.FFV)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setFFV(rsCpProcess.getString(
                             ConstantesAssets.FFV).trim());
              if (rsCpProcess.getString(ConstantesAssets.ES) != null
                        && !rsCpProcess.getString(ConstantesAssets.ES)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setES(rsCpProcess.getString(
                             ConstantesAssets.ES).trim());
              javaIntra.setI(ConstantesAssets.N);
              javaIntra.setN(ConstantesAssets.BLANK);
              javaIntra.setC(ConstantesAssets.BLANK);
              javaIntra.setCO(ConstantesAssets.BLANK);
              javaIntra.setFI(ConstantesAssets.BLANK);
              return javaIntra;
    Please see the code
    Siva

  • WL 6.1 sp3 and ResultSet.next()

    Has anyone else had a problem with this call ?
    I'm running this on Win2000 and Oracle 8.1.6.
    ResultSet.next() seems to return true even after the cursor has passed the last row in the set. This was not an issue with WL6.1 sp1.

    I got the same problem. But finally I found that this is the problem with WL 6.1. This is resolved in sp3.
    So please verify the exact version of weblogic you are using.
    Note : Start weblogic from some sample domain before executing the following.
    java -classpath <wl_install_dir>/wlserver6.1/lib/weblogic.jar weblogic.Admin -url T3://<host>:<port> VERSION
    You should get similar to....
    WebLogic Server 6.1 SP3 06/19/2002 22:25:39 #190835
    WebLogic XML Module 6.1 SP3 06/19/2002 22:39:10 #190835

  • ResultSet.next was not called

    I have this query ://Attempt The DB insert
    ResultSet rs = stmt.executeQuery("SELECT lhh_demo_id_seq.nextval from dual");
    String Demo_ID = rs.getString(1);
    while(rs.next()) {
    while (i < 2) {
    i++;
    rs.close();
    try
    Date date = dt.parse(birth);
    System.out.println("date " + date);
    stmt.executeUpdate( "insert into lhh_demo_reg values (" + Demo_ID + "," + RegNo + "," + Name + ",to_date('" + date+"','DD-Mon-YYYY')," + Center_ID + ")");
    catch(Exception e){}
    // Now Register a NULL Admission Record
    i = 0;
    rs = stmt.executeQuery("SELECT lhh_adm_id_seq.nextval from dual");
    String Adm_ID = rs.getString(1);
    while(rs.next()) {
    rs.close();
    stmt.executeUpdate("insert into lhh_adm_reg values (" + Adm_ID + "," + Center_ID +" , " + Demo_ID + ")");
    // Now Register a NULL Procedure Record
    i = 0;
    rs = stmt.executeQuery("SELECT lhh_proc_id_seq.nextval from dual");
    String Proc_ID = rs.getString(1);
    while(rs.next()) {
    while (i < 2) {
    i++;
    rs.close();
    stmt.executeUpdate("insert into lhh_proc_reg values (" + Proc_ID + "," + Center_ID + "," + Demo_ID + "," + Adm_ID +")");
    //Now Register a NULL Lesion Record
    i = 0;
    rs = stmt.executeQuery("SELECT lhh_les_id_seq.nextval from dual");
    String Les_ID = rs.getString(1);
    while(rs.next()) {
    while (i < 2) {
    i++;
    rs.close();
    but i keep getting ResultSet.next was not called...can anyone help please?

    I'm not sure what exactly you are trying to do ... but ...
    You seem to have several ResultSets in action. The first step is to find which of your "selects" is giving this exception. So, go ahead a enclose your statements within a try catch finally block. Use the finally block to close your result set (if not null).
    Once you narrow down the offending code, post back with the offending part of the code & the result you got with stack trace (if you still can't figure out what's happenning)
    HTH
    --Das                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Resultset.next() Issue

    Okay I have narrow my issue down to activity involved with the resultset.next() method. What is happening is I am working through a small resultset--3 records. These records are made up of columns from 3 seaprate tables (9 total). Some of these tables have many records (> 3K) in them. I moved the SQL statement in a store procedure so we can execute the query in a faster manner. The store procedure is returning the information in only 46ms. However, when I start looking through the resultset on the app server, it is taking 19K ms for the first time through the loop.
    I am at a lost to explain why the first iteration is taking so long. I have looked back at the SQL statement. I use alias names for the tables. I identify the column names in the select statement, but I do not use aliases for the column names. I am wondering if my problem is connected to the fact that the Oracle Driver
    maybe going back to get the column names the first time through the result set. I am not using the column name to index into the resultset. If my theory is right, this would explain the high latency. If I am wrong, I am stumped.
    Any suggestions or help explaining this would be greatly appreciated.
    As always, thanks for reading my post.
    Russ

    Execution of a CallableStatement (Procedure) is relatively fast. Getting ResultSet back is fast. But First iteration over the result set takes a lot of time comparing to the following iterations.
    Part of the code :
    long start=System.currentTimeMillis();
    int i=0;
    long local=System.currentTimeMillis();
    while(rs.next()){
    if (i==0){
    MetricsUtil.printTime("ResultSetRowHolder.getRows(ResultSet rs) ["+list.size()+" ]",local);
    local=System.currentTimeMillis();
    hol=new ResultSetRowHolder(rs);
    list.add(hol);
    i++;
    if (i%100==0){
    MetricsUtil.printTime("ResultSetRowHolder.getRows(ResultSet rs) ["+list.size()+" ]",local);
    local=System.currentTimeMillis();
    MetricsUtil.printTime("ResultSetRowHolder.getRows(ResultSet rs) ["+list.size()+" ]",start);
    Printouts
    Metrics << QueryHelper.executeStatement() >> Total time -> 2.836 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [0 ] >> Total time -> 13.867 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [100 ] >> Total time -> 0.48 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [200 ] >> Total time -> 0.44 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [300 ] >> Total time -> 0.47 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [400 ] >> Total time -> 0.38 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [500 ] >> Total time -> 0.37 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [600 ] >> Total time -> 0.38 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [700 ] >> Total time -> 0.35 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [800 ] >> Total time -> 0.34 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [900 ] >> Total time -> 0.32 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1000 ] >> Total time -> 0.34 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1100 ] >> Total time -> 0.41 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1200 ] >> Total time -> 0.32 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1230 ] >> Total time -> 14.340 sec

  • JDBC ResultSet.next() Error

    Can anyone help me with this error? I am running this in AIX box (java 1.3) using OCI to VMS RDB Server. I get this error when looping through the ResultSet.next().
    Thanks
    --Elie
    Exception in thread "main" java.sql.SQLException: ORA-09100: Message 9100 not found; No message file for product=NATCONN, facility=GTW
    %SYSTEM-F-NOMSG, Message number 0000C1C4
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java(Compiled Code))
    at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java(Compiled Code))
    at oracle.jdbc.oci8.OCIDBAccess.fetch(OCIDBAccess.java(Compiled Code))
    at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java(Compiled Code))
    at mbr.main(mbr.java(Compiled Code))

    I got it resolved by using NVL function on each of my DATE columns. I found a log from the RDB server complaining about dates. The NVL seems did the trick.
    Thanks again for your reply.
    --Elie                                                                                                                                                                                                                                                                                                                                                                                                           

  • Private Room throws NullPointerException

    Hi,
    I have created a private room and it was sucessfull. i am able to see the room without any problem. but when others(non-members) go to their rooms directory, it throws NullPointerException. This problem is only for private rooms only.
    we are using SP 17
    The exception is
    java.lang.NullPointerException
         at com.sap.ip.collaboration.roomui.api.util.properties.RoomResourceProperties.getPropertyValueAsString(RoomResourceProperties.java:53)
         at com.sap.ip.collaboration.roomui.api.util.properties.RoomResourceProperties.getRoomPrivacy(RoomResourceProperties.java:33)
         at com.sap.netweaver.coll.roomui.api.uicommands.UIRequestMembershipCommand.isExecutable(UIRequestMembershipCommand.java:67)
         at com.sapportals.wcm.rendering.uicommand.UIGroupCommand.getResourceCommands(UIGroupCommand.java:78)
         at  ..............
    can anyone reply what might be the reason be?
    Thank you.
    Saravana.
    Edited by: Saravana Parthiban Palaniswamy on Feb 4, 2009 1:22 PM
    Edited by: Saravana Parthiban Palaniswamy on Feb 4, 2009 1:26 PM

    Hi,
    If u goes to room directory in collaboration, there is a tab called Restricted Rooms. End of the room name there is context menu if u click that, it will show the menu there you can see the option called “Request Membership”. If you click that, corresponding room owner will receive the mail if he/she enabled the mail properties.
    If the answer helps your Question, provide the points.
    Regards,
    Kathiresan R

  • CreateEntityManagerFactory throws NullPointerException for ejb3 jse client

    This question has been posted to the Toplink/jpa forum without any reply.
    Dear experts!
    I am trying to create a java standard edition client, to test outside the weblogic server, my ejb 3 entities, declared as shown in the following persistence.xml.
    The java code follows also. I have read about some relevant bugs in eclipselink back in 2006, or 7 or 8 and mostly unanswered threads :
    CreateEntityManagerFactory null pointer exception and
    Returned null to createEntityManagerFactory about tomcat and oc4j.
    Persistence.createEntityManagerFactory() throw NullPointerException in oc4j
    I am using JDeveloper 11g Studio Edition Version 11.1.1.3.0, Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660.
    Any helping hand available?
    Thank you very much in advance!
    NA
    package chapter12javaseclient;
    import actionbazaar.buslogic.BidException;
    import actionbazaar.persistence.Bid;
    import actionbazaar.persistence.Bidder;
    import actionbazaar.persistence.Item;
    import java.util.HashMap;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    import org.eclipse.persistence.config.EntityManagerProperties;
    public class PlaceBidBeanJavaSE {
    private static EntityManagerFactory emf;
    private static EntityManager em;
    public static void main(String[] args) {
    String userId= "idiot";
    Long itemId = new Long (1);
    Double bidPrice = 2001.50;
    try {
    if (emf == null){
    emf = Persistence.createEntityManagerFactory("actionBazaar");
    System.out.println("EntityManagerFactory created!");
    getEntityManager();
    System.out.println("EntityManager created!");
    addBid(userId,itemId,bidPrice);
    commitTransaction();
    } finally {
    // close the EntityManager when done
    em.close();
    emf.close();
    private static void getEntityManager() {
    HashMap emProps = new HashMap();
    emProps.put(EntityManagerProperties.JDBC_USER, "ab");
    emProps.put(EntityManagerProperties.JDBC_PASSWORD, "ab");
    System.out.println("Creating entity manager");
    em = emf.createEntityManager(emProps);
    em.getTransaction().begin();
    private static void commitTransaction() {
    em.getTransaction().commit();
    private static Long addBid(String userId, Long itemId, Double bidPrice) throws BidException {
    Item item = em.find(Item.class,itemId);
    if (item == null)
    throw new BidException("Invalid Item Id");
    Bidder bidder = em.find(Bidder.class,userId);
    if (bidder == null)
    throw new BidException("Invalid Bidder Id");
    Bid bid = new Bid();
    bid.setItem(item);
    bid.setBidBidder(bidder);
    bid.setBidPrice(bidPrice);
    em.persist(bid);
    return bid.getBidId();
    <?xml version="1.0" encoding="UTF-8" ?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="actionBazaar" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>actionbazaar.persistence.Bid</class>
    <class>actionbazaar.persistence.Item</class>
    <class>actionbazaar.persistence.User</class>
    <class>actionbazaar.persistence.Bidder</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    <property name="eclipselink.target-server" value="WebLogic_10"/>
    <property name="eclipselink.target-database" value="Oracle11"/>
    <property name="javax.persistence.jdbc.driver"
    value="oracle.jdbc.OracleDriver"/>
    <property name="javax.persistence.jdbc.password"
    value="ab"/>
    <property name="javax.persistence.jdbc.url"
    value="jdbc:oracle:thin:@hera:1521:orcl"/>
    <property name="javax.persistence.jdbc.user" value="ab"/>
    <property name="eclipselink.logging.level" value="ALL"/>
    </properties>
    </persistence-unit>
    </persistence>

    A solution might be found here:
    Re: createEntityManagerFactory() throws NullPointerException for ejb jse client
    Re: createEntityManagerFactory() throws NullPointerException for ejb jse client
    NA
    [http://nickaiva.blogspot.com/]

  • CreateEntityManagerFactory() throws NullPointerException for ejb jse client

    Dear experts!
    I am trying to create a java standard edition client, to test outside the weblogic server, my ejb 3 entities, declared as shown in the following persistence.xml.
    The java code, and stacktrace follows also. I have read about some relevant bugs in eclipselink back in 2006, or 7 or 8 and mostly unanswered threads :
    CreateEntityManagerFactory null pointer exception and
    Returned null to createEntityManagerFactory about tomcat and oc4j.
    Persistence.createEntityManagerFactory() throw NullPointerException in oc4j
    I am using JDeveloper 11g Studio Edition Version 11.1.1.3.0, Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660.
    Any helping hand available?
    Thank you very much in advance!
    NA
    package chapter12javaseclient;
    import actionbazaar.buslogic.BidException;
    import actionbazaar.persistence.Bid;
    import actionbazaar.persistence.Bidder;
    import actionbazaar.persistence.Item;
    import java.util.HashMap;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    import org.eclipse.persistence.config.EntityManagerProperties;
    public class PlaceBidBeanJavaSE {
    private static EntityManagerFactory emf;
    private static EntityManager em;
    public static void main(String[] args) {
    String userId= "idiot";
    Long itemId = new Long (1);
    Double bidPrice = 2001.50;
    try {
    if (emf == null){
    emf = Persistence.createEntityManagerFactory("actionBazaar");
    System.out.println("EntityManagerFactory created!");
    getEntityManager();
    System.out.println("EntityManager created!");
    addBid(userId,itemId,bidPrice);
    commitTransaction();
    } finally {       
    // close the EntityManager when done
    em.close();
    emf.close();
    private static void getEntityManager() {
    HashMap emProps = new HashMap();
    emProps.put(EntityManagerProperties.JDBC_USER, "ab");
    emProps.put(EntityManagerProperties.JDBC_PASSWORD, "ab");
    System.out.println("Creating entity manager");
    em = emf.createEntityManager(emProps);
    em.getTransaction().begin();
    private static void commitTransaction() {
    em.getTransaction().commit();
    private static Long addBid(String userId, Long itemId, Double bidPrice) throws BidException {
    Item item = em.find(Item.class,itemId);
    if (item == null)
    throw new BidException("Invalid Item Id");
    Bidder bidder = em.find(Bidder.class,userId);
    if (bidder == null)
    throw new BidException("Invalid Bidder Id");
    Bid bid = new Bid();
    bid.setItem(item);
    bid.setBidBidder(bidder);
    bid.setBidPrice(bidPrice);
    em.persist(bid);
    return bid.getBidId();
    <?xml version="1.0" encoding="UTF-8" ?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="actionBazaar" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>actionbazaar.persistence.Bid</class>
    <class>actionbazaar.persistence.Item</class>
    <class>actionbazaar.persistence.User</class>
    <class>actionbazaar.persistence.Bidder</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    <property name="eclipselink.target-server" value="WebLogic_10"/>
    <property name="eclipselink.target-database" value="Oracle11"/>
    <property name="javax.persistence.jdbc.driver"
    value="oracle.jdbc.OracleDriver"/>
    <property name="javax.persistence.jdbc.password"
    value="ab"/>
    <property name="javax.persistence.jdbc.url"
    value="jdbc:oracle:thin:@hera:1521:orcl"/>
    <property name="javax.persistence.jdbc.user" value="ab"/>
    <property name="eclipselink.logging.level" value="ALL"/>
    </properties>
    </persistence-unit>
    </persistence>
    The log output follows:
    C:\Oracle\Middleware\jdev_11gR1\jdk160_18\bin\javaw.exe -client -classpath C:\MyWork\11g\ejb3inaction\.adf;C:\MyWork\11g\ejb3inaction\Chapter12JavaSEClient\classes;C:\MyWork\11g\ejb3inaction\Chapter12\classes;C:\Oracle\Middleware\jdev_11gR1\modules\javax.ejb_3.0.1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\com.oracle.toplink_1.0.0.0_11-1-1-3-0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\org.eclipse.persistence_1.0.0.0_2-0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\com.bea.core.antlr.runtime_2.7.7.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.toplink_11.1.1\javax.persistence_2.0_preview.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.xdk_11.1.0\xmlparserv2.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.xdk_11.1.0\xml.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.jsf_1.0.0.0_1-2.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.enterprise.deploy_1.2.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.interceptor_1.0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.jms_1.1.1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.jsp_1.1.0.0_2-1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.jws_2.0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.activation_1.1.0.0_1-1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.mail_1.1.0.0_1-4-1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.xml.soap_1.3.1.0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.xml.rpc_1.2.1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.xml.ws_2.1.1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.management.j2ee_1.0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.resource_1.5.1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.servlet_1.0.0.0_2-5.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.transaction_1.0.0.0_1-1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.xml.stream_1.1.1.0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.security.jacc_1.0.0.0_1-1.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.xml.registry_1.0.0.0_1-0.jar;C:\Oracle\Middleware\jdev_11gR1\modules\javax.persistence_1.0.0.0_1-0-2.jar;C:\Oracle\Middleware\jdev_11gR1\wlserver_10.3\server\lib\weblogic.jar;C:\Oracle\Middleware\jdev_11gR1\wlserver_10.3\server\ext\jdbc\oracle\11g\ojdbc6.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n-collation.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n-lcsd.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n-mapping.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n-servlet.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n-translation.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n-utility.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.odl_11.1.1\ojdl.jar;C:\Oracle\Middleware\jdev_11gR1\oracle_common\modules\oracle.dms_11.1.1\dms.jar -Djavax.net.ssl.trustStore=C:\Oracle\Middleware\jdev_11gR1\wlserver_10.3\server\lib\DemoTrust.jks chapter12javaseclient.PlaceBidBeanJavaSE
    [EL Finest]: 2010-06-25 09:23:10.495--ServerSession(229902)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit actionBazaar; session file:/C:/MyWork/11g/ejb3inaction/Chapter12JavaSEClient/classes/_actionBazaar; state Initial; factoryCount 0
    [EL Finest]: 2010-06-25 09:23:10.518--ServerSession(229902)--Thread(Thread[main,5,main])--property=eclipselink.orm.throw.exceptions; default value=true
    [EL Finer]: 2010-06-25 09:23:10.532--ServerSession(229902)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/C:/MyWork/11g/ejb3inaction/Chapter12JavaSEClient/classes/
    [EL Finer]: 2010-06-25 09:23:10.537--ServerSession(229902)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/C:/MyWork/11g/ejb3inaction/Chapter12JavaSEClient/classes/
    [EL Config]: 2010-06-25 09:23:10.652--ServerSession(229902)--Thread(Thread[main,5,main])--The access type for the persistent class [class actionbazaar.persistence.Item] is set to [PROPERTY].
    [EL Config]: 2010-06-25 09:23:10.696--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to many mapping element [method getCategorySet] is being defaulted to: class actionbazaar.persistence.Category.
    [EL Config]: 2010-06-25 09:23:10.702--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [method getBids] is being defaulted to: class actionbazaar.persistence.Bid.
    [EL Config]: 2010-06-25 09:23:10.71--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [method getSeller] is being defaulted to: class actionbazaar.persistence.Seller.
    [EL Config]: 2010-06-25 09:23:10.71--ServerSession(229902)--Thread(Thread[main,5,main])--The access type for the persistent class [class actionbazaar.persistence.User] is set to [PROPERTY].
    [EL Config]: 2010-06-25 09:23:10.711--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [method getCategories] is being defaulted to: class actionbazaar.persistence.Category.
    [EL Config]: 2010-06-25 09:23:10.716--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to one mapping element [method getBillingInfo] is being defaulted to: class actionbazaar.persistence.BillingInfo.
    [EL Config]: 2010-06-25 09:23:10.717--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to one mapping element [method getContactInfo] is being defaulted to: class actionbazaar.persistence.ContactInfo.
    [EL Config]: 2010-06-25 09:23:10.718--ServerSession(229902)--Thread(Thread[main,5,main])--The access type for the persistent class [class actionbazaar.persistence.Bidder] is set to [PROPERTY].
    [EL Config]: 2010-06-25 09:23:10.72--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [method getBids] is being defaulted to: class actionbazaar.persistence.Bid.
    [EL Config]: 2010-06-25 09:23:10.721--ServerSession(229902)--Thread(Thread[main,5,main])--The access type for the persistent class [class actionbazaar.persistence.Bid] is set to [PROPERTY].
    [EL Config]: 2010-06-25 09:23:10.721--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [method getBidBidder] is being defaulted to: class actionbazaar.persistence.Bidder.
    [EL Config]: 2010-06-25 09:23:10.721--ServerSession(229902)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [method getItem] is being defaulted to: class actionbazaar.persistence.Item.
    [EL Config]: 2010-06-25 09:23:10.722--ServerSession(229902)--Thread(Thread[main,5,main])--The alias name for the entity class [class actionbazaar.persistence.Item] is being defaulted to: Item.
    [EL Config]: 2010-06-25 09:23:10.746--ServerSession(229902)--Thread(Thread[main,5,main])--The alias name for the entity class [class actionbazaar.persistence.Bidder] is being defaulted to: Bidder.
    [EL Config]: 2010-06-25 09:23:10.746--ServerSession(229902)--Thread(Thread[main,5,main])--The alias name for the entity class [class actionbazaar.persistence.User] is being defaulted to: User.
    [EL Config]: 2010-06-25 09:23:10.753--ServerSession(229902)--Thread(Thread[main,5,main])--The table name for entity [class actionbazaar.persistence.Bidder] is being defaulted to: USERS.
    [EL Config]: 2010-06-25 09:23:10.753--ServerSession(229902)--Thread(Thread[main,5,main])--The discriminator column name for the root inheritance class [class actionbazaar.persistence.Bidder] is being defaulted to: DTYPE.
    [EL Config]: 2010-06-25 09:23:10.755--ServerSession(229902)--Thread(Thread[main,5,main])--The primary key column name for the inheritance class [class actionbazaar.persistence.Bidder] is being defaulted to: USER_ID.
    [EL Config]: 2010-06-25 09:23:10.755--ServerSession(229902)--Thread(Thread[main,5,main])--The foreign key column name for the inheritance class [class actionbazaar.persistence.Bidder] is being defaulted to: USER_ID.
    [EL Config]: 2010-06-25 09:23:10.758--ServerSession(229902)--Thread(Thread[main,5,main])--The alias name for the entity class [class actionbazaar.persistence.Bid] is being defaulted to: Bid.
    Exception in thread "main" java.lang.NullPointerException
         at chapter12javaseclient.PlaceBidBeanJavaSE.main(PlaceBidBeanJavaSE.java:43)
    Process exited with exit code 1.

    Thank you for your reply!
    The client now works correctly. It seems that the line
    em = emf.createEntityManager(emProps);//
    throws an exception when no argument is given for em = emf.createEntityManager();// emProps missing!
    There was also a warning in jdev editor, about the line you mentioned:
    <property name="eclipselink.target-server" value="WebLogic 10"/>
    Carry on with your good work!
    The updated persistence.xml and java source code shown below:
    <?xml version="1.0" encoding="UTF-8" ?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="actionBazaar" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>actionbazaar.persistence.Bid</class>
    <class>actionbazaar.persistence.Item</class>
    <class>actionbazaar.persistence.User</class>
    <class>actionbazaar.persistence.Bidder</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    <property name="eclipselink.target-database" value="Oracle11"/>
    <property name="javax.persistence.jdbc.driver"
    value="oracle.jdbc.OracleDriver"/>
    <property name="javax.persistence.jdbc.password"
    value="29E8BD11B89A62E3862F19C4F84B7DB0"/>
    <property name="javax.persistence.jdbc.user" value="ab"/>
    <property name="eclipselink.logging.level" value="ALL"/>
    <property name="eclipselink.orm.validate.schema" value="true"/>
    <property name="javax.persistence.jdbc.url"
    value="jdbc:oracle:thin:@hera:1521:orcl"/>
    </properties>
    </persistence-unit>
    </persistence>
    package chapter12javaseclient;
    import actionbazaar.buslogic.BidException;
    import actionbazaar.persistence.Bid;
    import actionbazaar.persistence.Bidder;
    import actionbazaar.persistence.Item;
    import java.util.HashMap;
    import java.util.Hashtable;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    import org.eclipse.persistence.config.EntityManagerProperties;
    public class PlaceBidBeanJavaSE {
    private static EntityManagerFactory emf;
    private static EntityManager em;
    private static Hashtable emProps = new Hashtable();
    public static void main(String[] args) {
    String userId= "idiot";
    Long itemId = new Long (2);
    Double bidPrice = 2002.50;
    try {
    if (emf == null){
    emf = Persistence.createEntityManagerFactory("actionBazaar");
    System.out.println("EntityManagerFactory created!");
    getEntityManager();
    System.out.println("EntityManager created!");
    addBid(userId,itemId,bidPrice);
    commitTransaction();
    } finally {       
    // close the EntityManager when done
    em.close();
    emf.close();
    private static void getEntityManager() {
    try {
    System.out.println("Creating entity manager");
    em = emf.createEntityManager(emProps);// if argument is missing exception is thrown!
    em.getTransaction().begin();
    } catch (Exception ne) {
    // TODO: Add catch code
    ne.printStackTrace();
    private static void commitTransaction() {
    em.getTransaction().commit();
    private static Long addBid(String userId, Long itemId, Double bidPrice) throws BidException {
    Item item = em.find(Item.class,itemId);
    if (item == null)
    throw new BidException("Invalid Item Id");
    Bidder bidder = em.find(Bidder.class,userId);
    if (bidder == null)
    throw new BidException("Invalid Bidder Id");
    Bid bid = new Bid();
    bid.setItem(item);
    bid.setBidBidder(bidder);
    bid.setBidPrice(bidPrice);
    em.persist(bid);
    return bid.getBidId();
    NA
    [http://nickaiva.blogspot.com/]

  • Error message ResultSet.next not called

    I am a student learning java and am currently working on an assignement where I need to write jdbc programs that connect to an oracle database. The error message that I am getting is:
    ResultSet.next was not called.
    I do not know why I am getting this message. I wrote a simpler program to try to find the error, but I still got it again. Here's the part of the program:
    ResultSet rset = stmt.executeQuery ("SELECT billing_id_seq.NEXTVAL Next_SeqNumber "+
                             "FROM Dual");
    int sequenceNumber=rset.getInt("Next_SeqNumber");
         while(rset.next()){
    System.out.println(sequenceNumber);
    Any ideas would be helpful. Thanks very much!

    I am not really sure if it is okay to post the whole program on this message board, but here it is:
    import java.sql.*;     //Import Java's JDBC classes
    public class CalculateEnrollFinalGrades {
    public static void main(String[] args) {
    //Invoke the processEnrollRecords() method
         processEnrollRecords();
    } //end main()
    // The following method issues a SQL SELECT statement to the database that returns the section_id
    // and student_id for ALL rows from the enrollment_copy table. For each row received back in the
    // result set, a call should be made to the updateEnrollFinalGrade() method. See below for
    // information about what the that method does and what arguments it takes.
    public static void processEnrollRecords() {
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver"); // Load the Oracle JDBC driver
    catch (java.lang.ClassNotFoundException e) {
    System.out.println(e.getMessage());
    try {
    //Create the connection and statement objects
         Connection conn= DriverManager.getConnection("jdbc:oracle:oci8:@", "STUDENT","LEARN");
         Statement stmt=conn.createStatement();
    //Execute a query in the CTA database which returns section_id and student_id for all
    //rows of the enrollment_copy table
         int sectId=0;
         int studId=0;
         String sqlQuery="SELECT section_id, student_id "+
                   "FROM enrollment_copy";
         ResultSet rset= stmt.executeQuery(sqlQuery);
    //For each record returned in the ResultSet object, pass
    //the current connection object along with each section_id and student_id as
    //arguments to a method called updateEnrollFinalGrade()
         //while(rset.next()){
         sectId=rset.getInt("section_id");
         studId=rset.getInt("student_id");
         updateEnrollFinalGrade(conn, sectId, studId);
         //}//close while
    //Close all resources before the program ends
         //conn.close();      //should this be kept open???
         stmt.close();
         rset.close();
         return;
    catch (java.sql.SQLException e) { 
    System.out.println(e.getMessage());
    } // end processEnrollRecords()
    // calculate a final_grade for the specified student
    // and section, and then it updates the enrollment_copy table with the final_grade.
    private static void updateEnrollFinalGrade(Connection conn_p, int sectionId_p, int studentId_p) {
    try {
         Connection conn= DriverManager.getConnection("jdbc:oracle:oci8:@", "STUDENT","LEARN");
         Statement stmt=conn.createStatement();
         //query returns one row which is the final grade for the course for a particular student id and section.
         String sqlQuery2= "SELECT "+
         "ROUND(SUM((SUM(g.numeric_grade))/(COUNT(g.grade_type_code))*(gtw.percent_of_final_grade/100))) finGrade "+
         "FROM grade g, grade_type_weight gtw "+
         "where g.section_id=gtw.section_id AND g.grade_type_code=gtw.grade_type_code "+
         "AND g.student_id=? "+
         "AND g.section_id=? "+
         "GROUP BY gtw.percent_of_final_grade";
         PreparedStatement pstmt=conn.prepareStatement(sqlQuery2);
         pstmt.setInt(1, studentId_p);
         pstmt.setInt(2, sectionId_p);     
         ResultSet rsetGrade=pstmt.executeQuery();
         int finalGrade=rsetGrade.getInt("finGrade");
    //Once the final_grade has been calculated, use a different PreparedStatement object to
    //store it in the related enrollment_copy record. You need to use a Prepared
    //Statement
         String sqlUpdate=      "Update enrollment_copy "+
                        "SET final_grade=? "+
                        "WHERE student_id=? AND section_id=?";
         PreparedStatement pstmtUpdate=conn.prepareStatement(sqlUpdate);
         pstmtUpdate.setInt(1,finalGrade);
         pstmtUpdate.setInt(2,studentId_p);
         pstmtUpdate.setInt(3,sectionId_p);
         pstmtUpdate.executeUpdate();
         pstmt.close();
         pstmtUpdate.close();          
         stmt.close();
         rsetGrade.close();
         return;
    } // end try block
    catch (java.sql.SQLException e) { 
    System.out.println(e.getMessage());
    } //end updateEnrollFinalGrade()
    } //end CalculateEnrollFinalGrades
    Thanks very mush for your help.

  • Control the loop of resultset.next( ); (method)

    Hai, guys
    I am using the ODBC database connection to (Excel Sheet) and i wanna get the records from it. My code is scucess but there is a problem in resultset.next() method.
    The thing is it retrieving all the data including the none data fields (null null), so finally it became a never ending loop.
    pls help me to get the data rang's records
    Statement stmnt = connexl.createStatement();
    String query = "SELECT * FROM [IJTS$]";
    stmnt.execute(query);
    ResultSet rsxl = stmnt.getResultSet();
    while(rsxl.next()) {
    String excelname = rsxl.getString(1);
    String excelcate = rsxl.getString(2);
    System.out.print(rsxl.getString(1));
    System.out.println(" "+rsxl.getString(2));
    }

    if null implies it has reached the last row, maybe you could check for null and break from the loop
    for example:
    while (rsxl.next()) {
      String excelname = rsxl.getString(1);
      String excelcate = rsxl.getString(2);
      if (excelname == null && excelcate == null) {
        break;
      } else {
        System.out.println(excelname + " " + excelcate);
    }

  • The ResultSet.next() returns false....

    Hai,
    I am working on jdbc. The connection credentials all correct, and its getting connected to the sybase without any problems. But I am not able to perform any 'select' or "update" statements...There are no exception or any errors...But the ResultSet.next() returns false and executeUpdate returns 0 . .
    I think you can help me.....Thanks...

    Yes the query is sameAs already pointed out, there are ONLY two possibilities.
    1. The query is not the same
    2. The database is not the same.
    You are making assumptions about what is going on and then drawing conclusions.
    You need to understand that you assumptions are wrong. So it doesn't matter what conclusion you draw.
    In terms of why the query isn't the same there could be any number of reasons but usually it is because you are passing in data and that data isn't what you think (assume) it is. It can also be that you are constructing the SQL and that construction is different. It could be that the environment that you use to test as settings which impact SQL.

  • Lockup in ojdbc14 Resultset.next()

    After several loops through the ResultSet handler, a subsequent call to ResultSet.next() results in a lockup.
    Below is a partial stack dump.
    Thread [Thread-14] (Suspended)
         oracle.jdbc.driver.SensitiveScrollableResultSet(oracle.jdbc.driver.ScrollableResultSet).prepare_refetch_statement(int) line: 2299 [local variables unavailable]
         oracle.jdbc.driver.SensitiveScrollableResultSet(oracle.jdbc.driver.ScrollableResultSet).refreshRowsInCache(int, int, int) line: 292
         oracle.jdbc.driver.SensitiveScrollableResultSet.refreshRow() line: 174
         oracle.jdbc.driver.SensitiveScrollableResultSet.handle_refetch() line: 255
         oracle.jdbc.driver.SensitiveScrollableResultSet.next() line: 82
         oracle.jdbc.driver.UpdatableResultSet.next() line: 251
         com.solcom.labelprintroom.DatabaseAccess.ordersForUserStatus(com.solcom.centraldb.CDBUser, java.lang.String) line: 291
    prepare_refetch_statement(int) is continuously looping between lines 2299, 2304, 2305.
    Connection is to an Oracle 8i (8.1.7) database.
    No exception is thrown and no timeout occurs. it merely loops continuously between the lines described in the Oracle driver.
    Is this a known problem? Is there a workaround?
    TIA
    AndyB

    "I have two DA classes with virtually the same code, just different queries."
    "In the other DA i do exactly the same..."Are these contradictory statements?
    Does anyone know if there is a problem with the Oracle
    Drivers or has anyone encountered a similair problem?Well, I am positive that -1 is not a problem for Oracle, it can use almost all the small negative numbers without error...
    Would it be possible to post a bit of your code to demonstrate how the code is different and how the SQL is different (or the same / not sure). There are infinite ways to code SQL with -1 in it, so what is important is exactly how you did it, which driver you are using, if you are using a Statement or PreparedStatement, if you are using connection pooling, etc.

Maybe you are looking for

  • No Data in PDF file in FTP server

    Hi All, I am trying to place a PDF file in FTP server. Used CONVERT_OTFSPOOLJOB_2_PDF to convert spool to PDF SCMS_TEXT_TO_XSTRING FTP_R3_TO_SERVER to transfer data to FTP. I am able to see PDF file in FTP and no of pages matches with that of R/3 but

  • ITunes 8.0 installation error --- network resource is unavailable / .msi

    Hello. When I was trying to install the latest version of iTunes I found an error message saying the following: "The feature you are trying to use is on a network resource that is unavailable. Click OK to try again, or enter an alternate path to a fo

  • How do I add more stuff to a iMAC G3?

    I have a problem trying to update my iMAC G3. It runs slow, so I wanted to know how much SDRAM memory I can put into to maximize it. It has a 30gb hard disk. Can it go any higher? If so, how much, and how do I install it? My goal is to modernize this

  • Safari 7 Crashes on Opening - Help Please!

    Hi, Safari is inexplicably crashing. The icon barely bounces and I get the message below. After looking at another thread, I thought it might have been my "Clean My Mac" app update that was causing the problem. I completely uninstalled that, but the

  • Error downloading wi-fi

    I'm trying to download wi-fi program to my laptop and I receive the following error message: The flow will not proceed due to Missing Hand-off Parameters: ssotoken PUID ssotoken value= PUID value= step value=wifireg I downloaded the program successfu