Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dewanshrawat15/1fd22ab2ac5996c99d63a702d1bd52cb to your computer and use it in GitHub Desktop.
Save dewanshrawat15/1fd22ab2ac5996c99d63a702d1bd52cb to your computer and use it in GitHub Desktop.
String url = "jdbc:mysql://localhost:3306/testdb?useSSL=false";
String user = "";
String password = "";
String author = "me";
String sql = "UPDATE table_name SET name = name1, email = email1, ...WHERE condition;";
try (Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement pst = con.prepareStatement(sql)) {
pst.setString(1, author);
pst.executeUpdate();
System.out.println("A new column inserted");
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(JdbcPrepared.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment