首页 > 数据库 >mysql操作源码

mysql操作源码

时间:2022-12-22 18:22:16浏览次数:47  
标签:String stmt 源码 static mysql 操作 null conn

package com.mysql;
import java.sql.*;
public class MysqlTest {
static final String driver="com.mysql.cj.jdbc.Driver";
static final String DB="jdbc:mysql://localhost/db10";
static final String user="root";
static final String password="lyf123456";
public static void main(String[] args){
Connection conn=null;
Statement stmt=null;
try{
Class.forName(driver);
conn=DriverManager.getConnection(DB,user,password);
stmt=conn.createStatement();
String sql="insert into Student values('scofied',45,89,100)";
stmt.executeUpdate(sql);
System.out.println("插入成功");

} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
finally {
if(stmt!=null){
try{
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}

标签:String,stmt,源码,static,mysql,操作,null,conn
From: https://www.cnblogs.com/lyf3701/p/16999356.html

相关文章