mysql的update
package test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class update { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } String sql="update hero set name=?,damage=?,hp=? where id=?"; try (Connection c= DriverManager.getConnection("jdbc:mysql://localhost:3306/how2java?characterEncoding=utf-8", "root","123456"); PreparedStatement ps=c.prepareStatement(sql);){ ps.setString(1,"哪吒"); ps.setFloat(3,5000f); ps.setInt(2,3000); ps.setInt(4,14); ps.execute(); } catch (SQLException e) { e.printStackTrace(); } } }