Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Tolls

Thread: JtextField and Table MS Access value.

  1. #1
    habiler is offline Member
    Join Date
    Sep 2016
    Posts
    44
    Rep Power
    0

    Default JtextField and Table MS Access value.

    Hello
    I ve an error between o m here 1 and i m here 2 (feature not supported) and he refuses the reactivating of statememt stmt.

    Who have a solution please

    Thanks

    Habiler

    [CODE]public final void FilljTxtNomPrenom() throws SQLException {
    affiche("i m here 1");
    //Statement stmt = conn.createStatement();
    ResultSet rs;
    rs = ps.executeQuery("SELECT * FROM Signaletique WHERE Matricule = ?");
    affiche("i m here 2");
    rs.setString(1, jTxtNomPrenom.getText());
    while ( rs.next() ) {
    String jTxtNomPrenom = rs.getString("Nom");
    System.out.println(jTxtNomPrenom );
    }
    // conn.close();

    }
    CODE]

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,964
    Rep Power
    31

    Default Re: JtextField and Table MS Access value.

    I ve an error
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: JtextField and Table MS Access value.

    Java Code:
    rs = ps.executeQuery("SELECT * FROM Signaletique WHERE Matricule = ?");
    That SQL needs to be part of a PreparedStatement.
    You then need to bind (set) the variable for Matricule, which is at index 1, before executing the SQL.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: JtextField and Table MS Access value.

    For people who read along: this is a continuation of the question here: http://www.java-forums.org/awt-swing...ess-value.html

    I gave you the exact syntax for your PreparedStatement. You could copy paste that. If you don't understand my answer just ask.

    Also: https://docs.oracle.com/javase/tutor.../prepared.html
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    habiler is offline Member
    Join Date
    Sep 2016
    Posts
    44
    Rep Power
    0

    Default Re: JtextField and Table MS Access value.

    Hello has all,

    How I could show the name of a customer in JtxtMatr with the name corresponding with "Matricule" in the db access (2).
    The Connection DB is OK.
    When I put in No. has the place of (LIKE " + ' " " + j. TxtMatr + ' " "); is also OK
    Is it necessary to usde the fct scanner?


    public final void FilljTxtNomPrenom() throws SQLException {
    // JTextField field;


    String sql1;
    sql1 = ("SELECT * FROM Signaletique WHERE Matricule LIKE " + "'" + jTxtMatr + "'");
    // affiche("Etape 2");
    System.out.println(jTxtMatr);
    PreparedStatement ps1 = conn.prepareStatement(sql1);

    try {


    ResultSet rs1 = ps1.executeQuery();

    while ( rs1.next() ) {

    jTxtNomPrenom.setText(rs1.getString(3)+" "+rs1.getString(4));
    affiche("Etape 3");

    //System.out.println(rs1.getString(1) +"* \t** "+rs1.getString(2) + rs1.getString(3)+ rs1.getString(4));
    }
    }
    catch (SQLException e ) {
    }
    finally {
    if (rs1 != null) { rs1.close(); }
    }
    }
    {
    JOptionPane.showMessageDialog(null, "Saved !!!!!");
    // conn.close();
    }
    Thank you for your help(assistant) >

    Habiler

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: JtextField and Table MS Access value.

    That's not using a prepared statement properly.
    SurfMan gave you the proper code in the other thread.

    That SQL will fail, because that query is:
    1. missing quotes around the text.
    2. Using the default toString of a JTextField, and not the text contained in the field. As also pointed out in that other thread.
    habiler likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. JtextField and Table MS Access value.
    By habiler in forum AWT / Swing
    Replies: 37
    Last Post: 11-18-2016, 09:33 AM
  2. Replies: 2
    Last Post: 04-03-2013, 04:33 PM
  3. how can i update my table with Jtextfield filtering?
    By sungirl in forum Advanced Java
    Replies: 4
    Last Post: 12-14-2010, 04:28 PM
  4. Replies: 1
    Last Post: 01-30-2009, 06:44 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
  •