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

    Exclamation "Column Not Found" exception in java

    hey all
    i have a search button in my java project that search the records in ms access table using ID but when i click on it i get an exception "Column Not Found"
    any ideas??

    BELOW IS MY CODE

    int ID =Integer.parseInt(sr_num.getText());

    String url = "jdbc:odbc:Cricket";
    String query = "SELECT * FROM [ODI Batting Stats] WHERE ID='"+sr_num+"'";
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn =DriverManager.getConnection(url, "","");
    Statement stmt = conn.createStatement();
    stmt.execute(query);
    ResultSet rs = stmt.getResultSet();
    boolean recordfound = rs.next();
    if (recordfound){
    sr_num.setText(rs.getString("ID"));
    fname.setText(rs.getString("First_Name"));
    lname.setText(rs.getString("Last_Name"));
    txt_age.setText(rs.getString("Age"));
    inn.setText(rs.getString("Innings"));
    txt_runs.setText(rs.getString("Runs"));
    avg.setText(rs.getString("Average"));
    sr.setText(rs.getString("Strike_Rate"));
    cent.setText(rs.getString("100's"));
    hcent.setText(rs.getString("50's"));
    txt_best.setText(rs.getString("Best"));
    txt_team.setText(rs.getString("Team"));

    }
    else{
    JOptionPane.showMessageDialog(null,"Record Not Found");
    }
    conn.close();
    } catch(java.lang.ClassNotFoundException ex){
    JOptionPane.showMessageDialog(null, ex.getMessage()) ;}
    catch(Exception ex){
    JOptionPane.showMessageDialog(null, ex.getMessage()); }

    AND THIS A SCREENSHOT OF MY DATABASE TABLE

    "Column Not Found" exception in java-untitled.jpg

    thanks in advance.

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

    Default Re: "Column Not Found" exception in java

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

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

    to get highlighting and preserve formatting.

    Note: the code should also call the printStackTrace() method in the catch block to get all available info about the exception.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    May 2016
    Location
    Brazil
    Posts
    16
    Rep Power
    0

    Default Re: "Column Not Found" exception in java

    Looks to me that you aren't using the correct DB field names.

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

    Default Re: "Column Not Found" exception in java

    so what should be called and where?? please can you help??

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

    Default Re: "Column Not Found" exception in java

    Don't hide those exceptions, i.e. do 'ex.printStackTrace()' in your catch-clauses and you'll see exactly what went wrong and where ...

    kind regards,

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

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

    Default Re: "Column Not Found" exception in java

    According to that screenshot you have columns called 'First Name', 'Last Name' and 'Strike Rate', and your code is requesting columns called 'First_Name", 'Last_Name' and 'Strike_Rate'.

    Printing the stack trace would have given you the line this occurred on, and so the column that had the issue, which would have made it easier to track down.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    claudiu's Avatar
    claudiu is offline Member
    Join Date
    May 2016
    Location
    RO
    Posts
    5
    Rep Power
    0

    Default Re: "Column Not Found" exception in java

    I'll say 100's and 50's could cause your exception,

    Java Code:
    cent.setText(rs.getString("100's"));
    hcent.setText(rs.getString("50's"));

Similar Threads

  1. Replies: 1
    Last Post: 11-02-2012, 11:38 PM
  2. Replies: 5
    Last Post: 12-21-2011, 06:44 PM
  3. Replies: 14
    Last Post: 04-08-2011, 06:01 PM
  4. Replies: 3
    Last Post: 03-21-2011, 01:48 PM
  5. Replies: 1
    Last Post: 11-20-2009, 07:58 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
  •