• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot convert from Prepared Statement to Prepared Statement

 
Clinton Morrison
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can connect to the database and execute a select statement. However when I try to write the following line
PreparedStatement ps = conn.prepareStatement(preparedSQL);
the compiler complains Cannot convert from Prepared Statement to Prepared Statement. Any help would be grately appreciated! Thanks in advance
Clinton

Using mysql 5.0
Using mysql-connector-java-5.0.7-bin
Using Eclipse 3.2



public class CustomerBean {
private Connection conn;

public void open() throws SQLException, NamingException {
if (conn != null)
return;
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mydb");
conn = ds.getConnection();
}

public Result getAll() throws SQLException, NamingException {
try {
open();
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM Customers");
return ResultSupport.toResult(result);
} finally {
close();
}
}

public void updateCustomer() throws SQLException, NamingException {
try {
open();
String preparedSQL = "UPDATE CUSTOMER SET CUST_ID = ? PHONE_NUMBER = ?, STREET_ADDRESS = ?, CITY = ?, STATE = ?";
PreparedStatement ps = conn.prepareStatement(preparedSQL);

} finally {
close();
}
}

public void close() throws SQLException {
if (conn == null)
return;
conn.close();
conn = null;
}
}
 
Paul Clapham
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you have written your own class, in the same package as the class you posted there, named "PreparedStatement". Then the compiler would be using your class when you just used the class name "PreparedStatement" with no package prefix.
 
Clinton Morrison
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you it worked! I should have been using
java.sql.PreparedStatement
Thanks
Clinton
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic