Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: load data in text view by clickink button

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Location
    Cambodia
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry load data in text view by clickink button

    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    public UserInfo() {
    initComponents();
    conn = ConnectSQL.getConnection();//import class construtor connect sql
    loadData();
    }

    private void loadData(){
    try{
    String sql = "select * from userinfo ";
    pst= conn.prepareStatement(sql);
    rs= pst.executeQuery();
    tbl_userinfo.setModel(DbUtils.resultSetToTableMode l(rs));
    }catch(Exception e){
    JOptionPane.showMessageDialog(this, e);
    }finally{
    try {
    rs.close();
    pst.close();
    } catch (Exception e) {
    }
    }

    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    try {
    String sql =" select min(presure),max(presure),avg(presure) from userinfo ";
    pst = conn.prepareStatement(sql);
    rs = pst.executeQuery();
    String min = rs.getString("min(presure)");
    txtMin.setText(min);
    String max = rs.getString("max(presure)");
    txtMin.setText(max);
    String avg = rs.getString("avg(presure)");
    txtMin.setText(avg);

    } catch (Exception e) {
    JOptionPane.showMessageDialog(null, e);
    }
    }
    tab pen.jpg


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: load data in text view by clickink button

    Quote Originally Posted by kim cheth View Post
                rs = pst.executeQuery();
                String min = rs.getString("min(presure)");
                txtMin.setText(min);
                String max = rs.getString("max(presure)");
                txtMin.setText(max);
                String avg = rs.getString("avg(presure)");
    You need to "move" to the first record with next() before you can get values. Otherwise you remain before the first record ... and it's an error to use getXyz().

    P.S.: and if you use an expression for the value in the query, please define an alias so that it's easy and more clear to get the value using a more appropriate label.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,469
    My Mood
    Mellow
    Thanks
    151
    Thanked 608 Times in 595 Posts

    Default Re: load data in text view by clickink button

    Welcome to the Forum! Please read this topic to learn how to post your code correctly along with other useful info for newcomers.

Similar Threads

  1. load from text into JTable
    By alaslipknot in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 6th, 2013, 04:22 AM
  2. Button to save data in text fields to a File
    By puuts in forum What's Wrong With My Code?
    Replies: 10
    Last Post: May 24th, 2013, 10:07 AM
  3. how can we load css file without pressing refresh button in web page
    By rajabetha in forum Other Programming Languages
    Replies: 1
    Last Post: May 15th, 2013, 07:30 PM
  4. how do i load my text file into my jtable.
    By legend101z in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 6th, 2013, 02:23 PM
  5. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM

Tags for this Thread