This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes Cannot convert from Prepared Statement to Prepared Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Cannot convert from Prepared Statement to Prepared Statement" Watch "Cannot convert from Prepared Statement to Prepared Statement" New topic
Author

Cannot convert from Prepared Statement to Prepared Statement

Clinton Morrison
Greenhorn

Joined: Jun 28, 2007
Posts: 24
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jun 28, 2007
Posts: 24
Thank you it worked! I should have been using
java.sql.PreparedStatement
Thanks
Clinton
 
wood burning stoves
 
subject: Cannot convert from Prepared Statement to Prepared Statement