使用步骤

  1.  创建工程,导入数据库对应的jar包

  2.  注册驱动:Class.forName("com.mysql.jdbc.Driver");  注:MySQL5之后驱动包,此行代码可以省略

  3.  获取连接:Connection conn = DriverManager.getConnection(url, username, password);

  4.  定义SQL语句:String sql = "update ...";

  5.  获取执行SQL对象:Statement stmt = conn.createStatement();

  6.  执行SQL:stmt.executeUpdate(sql);

  7.  处理返回结果

  8.  释放资源:stmt.close();  conn.close();