JAVA_JDBC1

JDBC :Java Date Base Connectivity

DB:加载驱动,获得DB连接

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {

private static final String URL="jdbc:mysql://127.0.0.1:3306/datebasename?useUnicode=true&characterEncoding=utf-8";
 private static final String USER="root";
 private static final String PASSWORD="";
 
 private static Connection conn=null;
 
 static {
  try {
   //1.加载驱动程序
   Class.forName("com.mysql.jdbc.Driver");
   //2.获得数据库的连接
   conn=DriverManager.getConnection(URL, USER, PASSWORD);
  } catch (ClassNotFoundException e) {
   e.printStackTrace();
  } catch (SQLException e) {
   e.printStackTrace();
  }
 }
 
 public static Connection getConnection(){
  return conn;
 }

}

MODEL-(增删改查CRUD—creat quary update delete)

时间: 2024-10-07 04:30:47

JAVA_JDBC1的相关文章