Update with parameters
In this chapter you will learn:
Update statement
import java.sql.Connection;
import java.sql.PreparedStatement;
/* java 2 s . com*/
public class Main {
public static void main(String[] argv) throws Exception {
Connection con = null;
PreparedStatement prepstmt;
prepstmt = con.prepareStatement("UPDATE employee SET Name = ? "
+ " WHERE Id = ?");
prepstmt.setString(1, "Smith");
prepstmt.setString(2, "1");
prepstmt.executeUpdate();
prepstmt.close();
con.close();
}
}
Next chapter...
What you will learn in the next chapter:
- How to do batch insert with PreparedStatement
- How to add batch with PreparedStatement without using for loop
Home » Java Tutorial » Statements, ResultSet, Exception, Warning