Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Cannot convert from Prepared Statement to Prepared Statement

 
Greenhorn
Posts: 24
  • 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;
}
}
 
Marshal
Posts: 25669
69
Eclipse IDE Firefox Browser MySQL Database
  • 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
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic