package com.avb.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/db1"; String username = "root"; String password = "root"; Connection conn = DriverManager.getConnection(url,username,password); //定义sql String sql = "update account set money = 2000 where id = 1"; //获取执行sql的对象Statement Statement stmt = conn.createStatement(); //执行sql stmt.executeUpdate(sql); //释放资源 stmt.close(); conn.close(); } }
标签:JDBC,java,String,--,jdbc,Statement,sql,conn,javaweb From: https://www.cnblogs.com/L-1906/p/17794146.html