Results 1 to 6 of 6
  1. #1
    Join Date
    May 2016
    Posts
    7
    Rep Power
    0

    Question Java pastes some stupid codes in database tables

    Hey everyone !!
    i have a semester project for java that inserts, updates and search records in a database table in MS Access using ODBC drivers. but i am facing a problem, whenever i click on insert it says "Inserted Successfully" but when i check it in the database table there is some stupid code inserted in the fields of table.....i think it pastes the text field details for every field in the database table now i dont know what to do? please help me out....

    following is my insert button code :

    String ID =sr_num.getText();
    String First_Name = fname.getText();
    String Last_Name = lname.getText();
    String Age =txt_age.getText();
    String Innings=inn.getText();
    String Runs=txt_runs.getText();
    String Average=avg.getText();
    String StrikeRate=sr.getText();
    String Century=cent.getText();
    String Halfcentury=hcent.getText();
    String best=txt_best.getText();
    String Team=txt_team.getText();
    String url = "jdbc:odbc:ODI";
    String query ="UPDATE ODI set First_Name='"+fname+"', Last_Name='"+lname+"',Age='"+txt_age+"',Innings='" +inn+"',Runs='"+txt_runs+"',Average'"+avg+"',Strik eRate='"+sr+"',Century='"+cent+"',Halfcentury'"+hc ent+"',Best='"+txt_best+"',Team='"+txt_team+"' WHERE ID='"+sr_num+"'";

    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn =DriverManager.getConnection(url, "","");
    java.sql.Statement stmt = conn.createStatement();
    stmt.execute(query);
    conn.close();
    JOptionPane.showMessageDialog(null,"UPDATED SUCCESSFULLY");
    }
    catch(java.lang.ClassNotFoundException ex)
    {
    JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());
    }

    and it is a screenshot of what i gets inserted in the fields of database table

    Java pastes some stupid codes in database tables-error.jpg

    please help me out.....

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java pastes some stupid codes in database tables

    Post moved from Netbeans section as it appears to be a programming problem, not a problem with Netbeans.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    it says "Inserted Successfully"
    Where does that message come from? I don't see it in your code.


    there is some stupid code inserted
    Can you copy what is inserted and post it here so we can see what you are talking about?
    Last edited by Norm; 05-15-2016 at 01:06 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Java pastes some stupid codes in database tables

    You should use the String FirstName instead of the JTextField fname variable in the construction of your SQL query (the same applies to the other JTextFields). And those codes aren't stupid; they are the String representation of those JTextFields ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    Join Date
    May 2016
    Posts
    7
    Rep Power
    0

    Default Re: Java pastes some stupid codes in database tables

    Thanks Jos, buddy you solved my problem :)

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

    Default Re: Java pastes some stupid codes in database tables

    And as a challenge, try and add someone whose name is O'Reilly.

    And then fix the issue by using a PreparedStatement.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Java pastes some stupid codes in database tables

    That again makes me think of this: https://xkcd.com/327/

    kind regards,

    Jos ;-)
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 2
    Last Post: 01-27-2010, 08:28 AM
  2. Listing tables of a database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-12-2008, 09:30 AM
  3. Replies: 0
    Last Post: 12-23-2007, 07:50 AM
  4. Replies: 1
    Last Post: 08-08-2007, 01:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •