[nbusers] Re: how to display "select" query

  • From: Witold Szczerba < >
  • To:
  • Subject: [nbusers] Re: how to display "select" query
  • Date: Mon, 8 Mar 2010 14:38:09 +0100
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=JNM595XPm9yI6Wa/Ya+t+txuvulRUULQFoJA1UC8epJVl5S1BKlcRMQNTb3bhVPSFH th8d/9EewtKnOV+jD8mozJpXOKLwKoISZ9WPb2Ql2oTir7mPMa4lZz3W4KlAOi3r+xI6 aeXobfZVAbeyl0OLUkOxPzHixwyk17D9Fl5Ig=

2010/3/8 adhi 
< >:
> hi..
> first, i'm not good in english
> so i'm sorry if my question is not understandable.. :P
> ====================
> i want to display all data in one table
> but...if i use this code
> ----------------------
> try {
>      Statement stmt;
>      ResultSet rsult;
>      Class.forName("com.mysql.jdbc.Driver");
>      String url =
>            "jdbc:mysql://localhost:3306/dbfinance";
>      Connection con =
>                     DriverManager.getConnection(
>                                 url,"root", "password");
>      stmt = con.createStatement();
>      rsult= stmt.executeQuery("SELECT * FROM `finance1`");
>       while (rsult.next()) {
>           String tipe_input = rsult.getString("tipe_input");
>           String input      = rsult.getString("input");
>           jTextField1.setText(tipe_input + input);
>           }
>       con.close();}
>        catch( Exception salah ) {
>        salah.printStackTrace();}
> ---------------------------
> j Text Field only display the last row of the data that i wanted
> any advice?
>
> thanx before..  [Rolling Eyes]
>

Mark has already answered to your problem, I just wanted to add you
should never handle connections (or whatever resources) that way:

WRONG:
try {
  Connection conn = .....
  ResultSet rs = ....
  some code...
  rs.close()
  conn.close();
} catch (...) {
  ...
}

The code above is very very bad, you should never write this way,
because when something wrong happens (exception) after your connection
is opened but before it is closed - the conn.close() will never be
invoked and the connection will hang somewhere, locking database
resources until you close your application. The situation like this is
called "resource leak" (you can find more about this if you like).

Write like this instead:

Connection conn = null;
ResultSet rs = null;
try {
  conn = ...
  rs = ...
} catch (...) { //this catch is actually optional
  ...
} finally {
  closeQuietly(rs);
  closeQuietly(conn);
}

The code above guarantees that there will be no unclosed connections.


[nbusers] how to display "select" query

adhi 03/08/2010

[nbusers] Re: how to display "select" query

Mark Wade 03/08/2010

[nbusers] Re: how to display "select" query

Witold Szczerba 03/08/2010

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close