Question: Populating Java Lists with SQL results


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Question: Populating Java Lists with SQL results

  1. #1
    MK Guest

    Question: Populating Java Lists with SQL results


    Is there a way of populating a Java list object with the results of a very
    basic SQL Query ?

  2. #2
    Paul Clapham Guest

    Re: Question: Populating Java Lists with SQL results

    Yes. Read through the results of the query and add them to the list object.

    PC2

    "MK" <majella.kavanagh@citicorp.com> wrote in message
    news:3c0266df$1@147.208.176.211...
    >
    > Is there a way of populating a Java list object with the results of a very
    > basic SQL Query ?




  3. #3
    MK Guest

    Re: Question: Populating Java Lists with SQL results


    Thanks for response. I have tried something along those lines but still end
    up with a blank list. Below is some of my code if anybody had any suggestions
    it would be most grate fully appreciated

    JList list1 = new JList()
    String s;


    ResultSet rs = stmt.executeQuery("select Name from Table1")

    while (rs.next())
    {
    s = rs.getString();
    list1.add(s)
    }



    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >Yes. Read through the results of the query and add them to the list object.
    >
    >PC2
    >
    >"MK" <majella.kavanagh@citicorp.com> wrote in message
    >news:3c0266df$1@147.208.176.211...
    >>
    >> Is there a way of populating a Java list object with the results of a

    very
    >> basic SQL Query ?

    >
    >



  4. #4
    Brent Worden Guest

    Re: Question: Populating Java Lists with SQL results

    Try
    s = rs.getString("Name"); or
    s = rs.getString(1);

    instead of
    s = rs.getString();


    Brent Worden
    http://www.brent.worden.org/



    MK wrote:

    > Thanks for response. I have tried something along those lines but still end
    > up with a blank list. Below is some of my code if anybody had any suggestions
    > it would be most grate fully appreciated
    >
    > JList list1 = new JList()
    > String s;
    >
    >
    > ResultSet rs = stmt.executeQuery("select Name from Table1")
    >
    > while (rs.next())
    > {
    > s = rs.getString();
    > list1.add(s)
    > }
    >
    >
    >
    > "Paul Clapham" <pclapham@core-mark.com> wrote:
    >
    >>Yes. Read through the results of the query and add them to the list object.
    >>
    >>PC2
    >>
    >>"MK" <majella.kavanagh@citicorp.com> wrote in message
    >>news:3c0266df$1@147.208.176.211...
    >>
    >>>Is there a way of populating a Java list object with the results of a
    >>>

    > very
    >
    >>>basic SQL Query ?
    >>>

    >>

    >



  5. #5
    MK Guest

    Re: Question: Populating Java Lists with SQL results


    Thanks alot for the response.
    It seems to work with a Java application however when I try to include similar
    code in a Java Applet I get an error message that applet can not be initialised
    or Null pointer, exception



    Brent Worden <brent@worden.org> wrote:
    >Try
    >s = rs.getString("Name"); or
    >s = rs.getString(1);
    >
    >instead of
    >s = rs.getString();
    >
    >
    >Brent Worden
    >http://www.brent.worden.org/
    >
    >
    >
    >MK wrote:
    >
    >> Thanks for response. I have tried something along those lines but still

    end
    >> up with a blank list. Below is some of my code if anybody had any suggestions
    >> it would be most grate fully appreciated
    >>
    >> JList list1 = new JList()
    >> String s;
    >>
    >>
    >> ResultSet rs = stmt.executeQuery("select Name from Table1")
    >>
    >> while (rs.next())
    >> {
    >> s = rs.getString();
    >> list1.add(s)
    >> }
    >>
    >>
    >>
    >> "Paul Clapham" <pclapham@core-mark.com> wrote:
    >>
    >>>Yes. Read through the results of the query and add them to the list object.
    >>>
    >>>PC2
    >>>
    >>>"MK" <majella.kavanagh@citicorp.com> wrote in message
    >>>news:3c0266df$1@147.208.176.211...
    >>>
    >>>>Is there a way of populating a Java list object with the results of a
    >>>>

    >> very
    >>
    >>>>basic SQL Query ?
    >>>>
    >>>

    >>

    >



  6. #6
    Paul Clapham Guest

    Re: Question: Populating Java Lists with SQL results

    This probably has nothing to do with JList and everything to do with applet
    security and configuration. Is your database on the same server where the
    applet is loaded from? Are you using an appropriate JDBC driver for an
    applet? Are you ignoring errors when you can't connect?

    PC2

    "MK" <majella.kavanagh@citicorp.com> wrote in message
    news:3c073798$1@147.208.176.211...
    >
    > Thanks alot for the response.
    > It seems to work with a Java application however when I try to include

    similar
    > code in a Java Applet I get an error message that applet can not be

    initialised
    > or Null pointer, exception





  7. #7
    MK Guest

    Re: Question: Populating Java Lists with SQL results


    Paul,

    The following is the code which I use to make the connection :

    strUrl = "jdbcdbc:" + strDSN;
    strUserName = "logon";
    strPassword = "";

    public void Open() //Opens the conection to the database
    {
    try
    {
    // Load the jdbc-odbc bridge driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    // Attempt to connect to a driver.
    con = DriverManager.getConnection( strUrl, strUserName,
    strPassword );

    // Create a Statement object so we can submit
    // SQL statements to the driver
    stmt = con.createStatement();

    }
    catch (SQLException ex)
    {
    while (ex != null)
    {
    System.out.println("SQL Exception: " + ex.getMessage() );
    ex = ex.getNextException();
    }
    }
    catch (java.lang.Exception ex)
    {
    ex.printStackTrace();
    }
    }


    Originally I was running the applet from a different server. However based
    on your suggestion I copied the code on to the same drive as the database
    but I am still getting the same error on the applet screen when I type in
    "appletviewer test.html" :"start: applet not initialised"
    When I look at the command line I see errors such as :
    java.lang.NullPointerException
    at java.awt.Container.addImpl(Container.java:442) etc

    If you have any suggestions as to what the problem may be please please let
    me know as this is driving me mad

    Thanks again





    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >This probably has nothing to do with JList and everything to do with applet
    >security and configuration. Is your database on the same server where the
    >applet is loaded from? Are you using an appropriate JDBC driver for an
    >applet? Are you ignoring errors when you can't connect?
    >
    >PC2
    >
    >"MK" <majella.kavanagh@citicorp.com> wrote in message
    >news:3c073798$1@147.208.176.211...
    >>
    >> Thanks alot for the response.
    >> It seems to work with a Java application however when I try to include

    >similar
    >> code in a Java Applet I get an error message that applet can not be

    >initialised
    >> or Null pointer, exception

    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center