Reputation: 139
package jdbcDemo;
import java.sql.*;
public class PreparedStatement {
public static void main(String[] args){
// using SQL to insert,edit,delete information from a database
Connection myConn =null;
PreparedStatement myStmt=null;
ResultSet myRs=null;
try{
// 1.make a connection to database
myConn= DriverManager.getConnection("jdbc:mysql://localhost:3306/shopping_cart","root","1578");
//2.create a statement
myStmt= myConn.prepareStatement("SELECT * FROM shopping_cart.customers where total_cost>? and items_number>?");
//3.set parameters
myStmt.setDouble(1,2);
myStmt.setDouble(2,40);
myRs=myStmt.executeQuery();
}
catch(Exception exc){
exc.printStackTrace();
}
}
In the step 2, I am trying to create a prepared statement, but got a "Type mismatch: cannot convert from java.sql.PreparedStatement to jdbcDemo. PreparedStatement" . I googled it , most of the answers say I should import java.sql.*, and I did but still got the answer.
Upvotes: 0
Views: 2839
Reputation: 75062
You defined your own PreparedStatement
, and it is confusing the compiler.
Change the name of your class or replace
PreparedStatement myStmt=null;
with
java.sql.PreparedStatement myStmt=null;
Upvotes: 3