Results 1 to 13 of 13
  1. #1
    jason.3dmagic is offline Member
    Join Date
    Oct 2009
    Posts
    30
    Rep Power
    0

    Question Problems while getting data from weblogic server when using connection pooling

    Hello,

    I am new to database connection pooling. I am using weblogic server, Java 1.6, MySql database. I have done connection pooling in weblogic server. The problem arise when I try to run select query I cannot fetch data in ResultSet. For insert it works fine...

    import java.io.Serializable;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Properties;

    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.sql.DataSource;

    public class DatabaseToText implements Serializable {

    public DatabaseToText() {
    super();
    // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {

    Connection conn;
    Statement stmt;
    ResultSet rs;
    String str1, str2;
    List l1 = new ArrayList();

    try {
    System.out.println("in try block");
    Properties prop = new Properties();



    prop.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    prop.put(Context.PROVIDER_URL, "t3://localhost:7001");

    System.out.println("properties are set ");

    Context ctx = new InitialContext(prop);
    System.out.println("b4 lookup(mysqljndi)");

    Object obj = ctx.lookup("mysqljndi"); // java:comp/env/CPDS
    System.out.println("afta lookup(mysqljndi)");

    DataSource ds = (DataSource) obj;
    conn = ds.getConnection();
    stmt = conn.createStatement();

    String query = "select * from logindb.userregister";
    System.out.println("query is = " + query);
    rs = stmt.executeQuery(query);

    System.out.println("size of rs is :: " + rs.getFetchSize());

    Iterator i = l1.iterator();
    Object obj2 = (Object) rs;
    System.out.println("values in rs are :: " + rs.getString(0));

    if (rs != null) {
    while (i.hasNext()) {
    l1.add(rs.getString(0));
    l1.add(rs.getString(1));

    // System.out.println("username is :: " + str1 + "password is : " + str2);
    }
    } else {
    System.out.println("no values get fetched");
    }
    ctx.close();

    } catch (Exception e) {
    e.printStackTrace();
    }

    }
    }


    This is the program and following is the output

    in try block
    properties are set
    b4 lookup(mysqljndi)
    afta lookup(mysqljndi)
    query is = select * from logindb.userregister
    size of rs is :: 0
    java.sql.SQLException: java.lang.ClassCastException: weblogic.jdbc.common.internal.ReaderBlockGetterImp l_811_WLStub cannot be cast to java.lang.String
    at weblogic.jdbc.rmi.SerialResultSet.getString(Serial ResultSet.java:130)
    at DatabaseToText.main(DatabaseToText.java:71)


    Console is showing errors....

    Please Help


    Regards, Jason

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You would get failures in this code regardless of whether it's using a pool or not
    Java Code:
    rs = stmt.executeQuery(query);
    
    System.out.println("size of rs is :: " + rs.getFetchSize());
    
    Iterator i = l1.iterator();
    Object obj2 = (Object) rs;
    // you have not called next() or first() or last() so there is no selected row
    System.out.println("values in rs are :: " + rs.getString(0));

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    The result set starts before the first record.
    You can't access any of the columns until you have called next()...which returns a boolean to say whether there is a next or not.

  4. #4
    jason.3dmagic is offline Member
    Join Date
    Oct 2009
    Posts
    30
    Rep Power
    0

    Exclamation

    Sorry I posted wrong code when i was playing with the code.....
    Following is the exact code


    Java Code:
    import java.io.Serializable;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Properties;
    
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.sql.DataSource;
    
    public class DatabaseToText implements Serializable {
    
      public DatabaseToText() {
        super();
        // TODO Auto-generated constructor stub
      }
    
      public static void main(String[] args) {
    
        Connection conn;
        Statement stmt;
        ResultSet rs;
        String str1, str2;
        List l1 = new ArrayList();
    
        try {
          System.out.println("in try block");
          Properties prop = new Properties();
    
         
    
          prop.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
          prop.put(Context.PROVIDER_URL, "t3://localhost:7001");
    
          System.out.println("properties are set  ");
    
          Context ctx = new InitialContext(prop);
          System.out.println("b4 lookup(mysqljndi)");
    
          Object obj = ctx.lookup("mysqljndi"); // java:comp/env/CPDS
          System.out.println("afta lookup(mysqljndi)");
    
          DataSource ds = (DataSource) obj;
          conn = ds.getConnection();
          stmt = conn.createStatement();
    
          String query = "select * from logindb.userregister";
          System.out.println("query is = " + query);
          rs = stmt.executeQuery(query);
    
          System.out.println("size of  rs is  ::   " + rs.getFetchSize());
    
          if (rs != null) {
            while (rs.next()) {
              str1 = rs.getString(0);
              str2 = rs.getString(1);
              System.out.println("username is :: " + str1 + "password is : " + str2);
            }
          } else {
            System.out.println("no values get fetched");
          }
          ctx.close();
    
        } catch (Exception e) {
          e.printStackTrace();
        }
    
      }
    }
    OUTPUT IN CONSOLE:::::

    in try block
    properties are set
    b4 lookup(mysqljndi)
    afta lookup(mysqljndi)
    query is = select * from logindb.userregister
    size of rs is :: 0
    java.sql.SQLException: weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception - with nested exception:
    [java.rmi.MarshalException: error marshalling return; nested exception is:
    java.io.NotSerializableException: com.mysql.jdbc.ResultSet]
    at weblogic.jdbc.rmi.SerialResultSet.next(SerialResul tSet.java:89)
    at DatabaseToText.main(DatabaseToText.java:69)

    The error is at line while(rs.next())
    Record is getting inserted but when i use select query i cannot get the output...
    Last edited by jason.3dmagic; 02-16-2010 at 05:43 AM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Is your connection pool on a separate server then?

    As it says, that MySQL result set isn't serializable.

  6. #6
    jason.3dmagic is offline Member
    Join Date
    Oct 2009
    Posts
    30
    Rep Power
    0

    Exclamation

    I am developing it on a single PC...
    Everything is installed on my PC

    Yes i agree that ResultSet is not serialized......
    but if you look at the console output closely the rs.getFetchSize() is giving 0.
    I have data in the table the getFetchSize() output should have been 1.

    Though I am able to insert data into database....

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    getFetchSize() does not return the row count. It tells you how many rows it will get from the database once you have scrolled through all the ones it has already supplied. So a fetch size of 10 will retrieve 10 rows, then 10 more once you have called next() 10 times, and so on.

    I suspect fetch size doesn't involve hitting the db, and also is only an int so is automatically serializable in any case. However actually fetching the data across with a next() isn't.

    You say you're on a single PC, however your code is not running inside weblogic, as in a normal webapp, so it still has to transfer from your web server to your app, albeit on the same machine.

  8. #8
    jason.3dmagic is offline Member
    Join Date
    Oct 2009
    Posts
    30
    Rep Power
    0

    Default

    SO, Tolls
    Please tell me how do I conquer the problem??
    I will really appreciate your help...

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    I can only assume this is happening because you are connecting to your data source in a wierd way. Why are you running a main() app against a connection pool on a server? It doesn't make architectural sense.

    The pool on weblogic is intended to be used by apps deployed on that same weblogic server, not to be used by an app external to weblogic.

  10. #10
    jason.3dmagic is offline Member
    Join Date
    Oct 2009
    Posts
    30
    Rep Power
    0

    Question Same error came....

    Hello Tolls,

    Thank you for replying. I tried what you had suggested. I configured weblogic server from myeclipse and run the program but it is again giving me error on the same line and for the same reason.
    I am very confused now. I tried every possible things i could do.

    Please help

    Thanks and Regards,
    Jason

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    If you're running a main() then it is not running in weblogic. It is an external app.

  12. #12
    jason.3dmagic is offline Member
    Join Date
    Oct 2009
    Posts
    30
    Rep Power
    0

    Arrow You solved mate.. thnaks a TON!!!!

    Hello Tolls,

    You solved it... Thank you very much...

    I was trying connection pooling in a simple java program later I tried for simple login program and started server from myeclipse internally. Guess wat it is running.
    Now I want to do connection pooling in JBoss. Do you know how to do connection pooling in JBoss?? I have know idea about how to do it in JBoss. :confused:

  13. #13
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

Similar Threads

  1. Connection pooling
    By neeti in forum Networking
    Replies: 1
    Last Post: 11-11-2009, 04:54 PM
  2. Replies: 7
    Last Post: 10-20-2009, 10:34 AM
  3. Replies: 0
    Last Post: 09-01-2008, 11:57 AM
  4. connection pooling
    By kal132 in forum JDBC
    Replies: 1
    Last Post: 06-27-2007, 02:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •