package com.itheima.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLOutput; import java.sql.Statement; public class JDBCDemo { public static void main(String[] args) throws Exception { //1注册驱动 Class.forName("com.mysql.jdbc.Driver"); //2 获取链接 String username="root"; String password="1234"; String url="jdbc.mysql://127.0.0.1:3306/db1"; Connection conn=DriverManager.getConnection(url,username,password); //3 定义Sql语句 String sql="update account set money = 2000 where id = 1"; //4 获取执行Sql的对象 Statement Statement stmt = conn.createStatement(); //5 执行SQL语句 int count=stmt.executeUpdate(sql);//获取执行的函数结果 //6 处理结果 System.out.println(count); //7 释放资源 stmt.close(); conn.close(); } }View Code
标签:JDBC,java,String,Statement,sql,import,JavaWeb5,conn From: https://www.cnblogs.com/lvlisn/p/16709397.html