i have a connection method like this:
public Connection getConnection(){
Connection con = null;
try {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:andre",User,Pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
and i want to user insert query with dynamic function, and i use code like this:
public void setInsert(String username, String password) throws SQLException{
Connection con = getConnection();
Statement stmt = con.createStatement();
String query = "INSERT INTO andre(username,password) VALUES("+username+","+password+")";
stmt.executeQuery(query);
con.close();
stmt.close();
}
and i test my code using jUnit.
@Test
public void insertTest() throws SQLException{
test.SetInsert(null, null);
}
why i get an error?, how i fix it. please help me. sorry if my grammar is so bad. Thanks for your answers.