1.java 连接mysql数据的方法
首先需要先下载mysql-connector-java架包。
2.在java中的连接语句。
public static void main(String[] args) throws Exception {
//1.导入架包
//2.注册驱动
Class.forName("com.mysql.jdbc.Driver");
//3.获取数据库连接对象
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","123456");
//4.sql语句
String sql="update acount set balance=balance-500 where id=1";
//5.创建执行sql的对象stateme
Statement statement=conn.createStatement();
//6.执行sql
int count=statement.executeUpdate(sql);
System.out.println(count);
//7.释放资源
statement.close();
conn.close();
}