jdbc连接数据库实现信息增删查改
jdbc连接数据库实现信息增删查改
利用jdbc连接数据库,实现信息表的增删查改
一、创建数据库java7,并在其中创建表tb_user
创建数据库java7,并在其中创建表tb_user
二、利用jdbc连接数据库,实现信息表的增删查改
- DBUtil.calss
package com.zhongruan;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBUtil {
private static String driver = "com.mysql.jdbc.Driver";
private static String url = "jdbc:mysql://localhost:3306/java7?useSSL=true&characterEncoding=utf-8";
private static String user = "root";
private static String password = "123";
public DBUtil() {
}
public static Connection get_Conn() throws SQLException {
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println("数据库连接成功" + conn);
return conn;
}
public static void get_CloseConn(ResultSet rs, PreparedStatement pstm, Connection conn) throws SQLException {
if (rs != null) {
rs.close();
}
if (pstm != null) {
pstm.close();
}
if (conn != null) {
conn.close();
}
}
public static void main(String[] args) {
try {
get_Conn();
} catch (SQLException var2) {
var2.printStackTrace();
}
}
static {
try {
Cla