Data type mismatch in criteria expression.

saroosh
saroosh used Ask the Experts™
on
in the data base i have the field balance as (number,double,decimal 2)

the variable
 double pbalance=Double.parseDouble(strbalance);

 strSQL="SELECT * FROM Accounts WHERE
 balance >='"+pbalance+"'";

i got this error :

javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
take out the single quotes around pbalance...you've accidently made it into a string.

Should be

strSQL="SELECT * FROM Accounts WHERE
balance >= " + pbalance;

Commented:
you should use prepared statements:

try {
 Connection con = DriverManager.getConnection(url);
 String query= "SELECT * FROM Accounts WHERE balance >= ?";
 PreparedStatement ps = con.prepareStatement(query);
 ResultSet rs = null;

 for(int i=0;i<10;i++) {
//  PreparedStatement Example
// change this to the right data type
   ps.setDouble(1,pbalance);
   rs = ps.executeQuery();
   while (rs.next()) {

   }
 }
} catch (SQLException sqle) {sqle.printStackTrace();}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial