package com.itheima.jdbc;//jdbc import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class JDBCDemo { public static void main(String[] args) throws Exception { //注册驱动 Class.forName("com.mysql.jdbc.Driver"); //获取链接 String url = "jdbc:mysql://127.0.0.1:3306/db2"; String username = "root"; String password = "123456"; Connection conn = DriverManager.getConnection(url,username,password); //定义sql语句 String sql = "update jdbc set name = '张三' where id = 1 "; //获取执行的对象 Statement Statement stmt = conn.createStatement(); //执行sql int count = stmt.executeUpdate(sql); //处理结果 System.out.println(count); //释放资源 stmt.close(); conn.close(); } }标签:jdbc,java,String,数据库,Statement,sql,链接,conn From: https://www.cnblogs.com/yzx-sir/p/16796241.html