Java实现数据库的增删改:
第一步:连接配置数据库如下
package com.itheima.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/*
JDBC快速入门
*/
public class JDBCdemo {
public static void main(String[] args) throws Exception {
//1.注册驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2.获取连接
String url="jdbc:mysql:///students";
String username="root";
String password="********";
Connection conn =DriverManager.getConnection (url,username,password);
//3.定义sql
String sql="update cnt set count=2000";
//4.获取执行sql的对象 Statement
Statement stmt = conn.createStatement();
//5.执行sql
int count = stmt.executeUpdate(sql);
//6.处理结果
System.out.println(count);
//7,释放资源
stmt.close();
conn.close();
}
}