| 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: 16482
|
|
|
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
|
 |
 |
|
|
subject: Cannot convert from Prepared Statement to Prepared Statement
|
|
|