Solved

Select SQL Prepared statement

Posted on 2004-04-22
5
164 Views
Last Modified: 2010-05-18
When I click on the button to retrieve information from my database using the below.  Nothing happens, no error message at all!!!  Can anyone help??  The listener is below this method

public void viewmemberSQL(){
                  
                        try     {

             Statement st = con.createStatement();
PreparedStatement ps5 = con.prepareStatement( "Select * from Members where Memberid = ?" );

          ps5.setInt(1, memberid2);
         

          ResultSet rs = ps5.executeQuery();
                      while (rs.next()) {
    viewmembertfield1.setText(rs.getString(1));
    viewmembertfield2.setText(rs.getString(2));
    viewmembertfield3.setText(rs.getString(3));
    viewmembertfield4.setText(rs.getString(4));
    viewmembertfield5.setText(rs.getString(5));
    viewmembertfield6.setText(rs.getString(6));
    viewmembertfield7.setText(rs.getString(7));
    viewmembertfield8.setText(rs.getString(8));
    viewmembertfield9.setText(rs.getString(9));
    viewmembertfield10.setText(rs.getString(10));
   
}
         st.close();
            con.close();

                           }

     catch (Exception e) {
            System.err.println("Got an exception! ");
            System.err.println(e.getMessage());


                    }

     finally{

          if(con != null)
          {
               try{
                    con.close();
          }

          catch(Exception ignored) {}
          }
          }

          }





                        class MemberviewDetails implements ActionListener
     {
         
**********************************************************************

      public MemberviewDetails() {

             }
          public void actionPerformed(ActionEvent e)
          {

         
         
          memberid = Integer.parseInt(viewmembertfield11.getText());
          viewmemberSQL();          

            }
   
  }
     
*************************************************************************

viewmemberbutton2 = new JButton("OK");
viewmemberbutton2.addActionListener(new MemberviewDetails());
0
Comment
Question by:mcowman
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10892279
Most likely you're getting no rows returned. Put a println in your while loop - if it doesn't print then you haven't
0
 

Author Comment

by:mcowman
ID: 10892670
Found the mistake, in the listener memberid is


          memberid = Integer.parseInt(viewmembertfield11.getText());



while in the statement is



          ps5.setInt(1, memberid2);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10892690
OK - you can have the Q deleted if you want
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11702956
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question