Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2006
    Posts
    8

    Question Unanswered: Can anyone finds the error

    Hi, I have error in my java program that is connected to MS Access ,it's in the Find query I got the following error message :

    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.



    public class FindRecord implements ActionListener {
    private ScrollingPanel fields;
    private JTextArea output;
    private Connection connection;

    public FindRecord( Connection c, ScrollingPanel f, JTextArea o )
    {
    connection = c;
    fields = f;
    output = o;
    }

    public void actionPerformed( ActionEvent e )
    {
    try {
    if ( !fields.CarID.getText().equals( "" ) ) {
    Statement statement =connection.createStatement();
    String query = "SELECT * FROM Static " +
    "WHERE CarID = '" +
    fields.CarID.getText() + "'";

    output.append( "\nSending query: " +
    connection.nativeSQL( query )
    + "\n" );

    ResultSet rs = statement.executeQuery( query );

    display( rs );

    output.append( "\nQuery successful\n" );
    statement.close();
    }
    else
    fields.CarID.setText( "Enter CarID here then press Find" );
    }
    catch ( SQLException sqlex ) {
    sqlex.printStackTrace();
    output.append( sqlex.toString() );
    }
    }

    // Display results of query. If rs is null
    public void display( ResultSet rs )
    {
    try {
    rs.next();

    int recordNumber = rs.getInt( 1 );

    if ( recordNumber != 0 ) {

    fields.CarID.setText( String.valueOf( recordNumber));
    fields.FirstName1.setText( rs.getString( 2 ) );
    fields.LastName1.setText( rs.getString( 3 ) );
    fields.FirstName2.setText( rs.getString( 4 ) );
    fields.LastName2.setText( rs.getString( 5 ) );
    fields.Location.setText( rs.getString( 6 ) );

    }
    else
    output.append( "\nNo record found\n" );
    }
    catch ( SQLException sqlex ) {
    sqlex.printStackTrace();
    output.append( sqlex.toString() );
    }
    }
    }

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What datatype is CarID?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2006
    Posts
    8
    CarID is a field in the access file ,data type : number

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Try this:
    Code:
    "WHERE CarID = " +
    fields.CarID.getText();
    instead of this:
    Code:
    "WHERE CarID = '" +
    fields.CarID.getText() + "'";
    By encapsulating your carID parameter in quotes, you are defining it as a string. Access probably doesn't like that...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Feb 2006
    Posts
    8
    Thank you very much Teddy you help me alot ,

Posting Permissions

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