hi everyone.
my issue is that when creating a prepared statement if i create a delete statement with a variable the code doesnt excute but instead if i provide it with a string it works fine. whats the problem.
this code doesnt seem to work
public void delCustomer(String id) throws Exception {
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/mydatabase?"
+ "user=sqldata&password=sqldatapw");
// Statements allow to issue SQL queries to the database
statement = connect.createStatement();
// PreparedStatements can use variables and are more efficient
preparedStatement = connect
.prepareStatement("delete from MYDATABASE.CUSTOMER where ID_NUMBER= ? ");
preparedStatement.setString(1, id);
preparedStatement.executeUpdate();
} catch (Exception e) {
throw e;
} finally {
close();
}
}
this work fine and i have debuged to see that in the last code id == 00002
public void delCustomer(String id) throws Exception {
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/mydatabase?"
+ "user=sqldata&password=sqldatapw");
// Statements allow to issue SQL queries to the database
statement = connect.createStatement();
// PreparedStatements can use variables and are more efficient
preparedStatement = connect
.prepareStatement("delete from MYDATABASE.CUSTOMER where ID_NUMBER= ? ");
preparedStatement.setString(1, "00002");
preparedStatement.executeUpdate();
} catch (Exception e) {
throw e;
} finally {
close();
}
}