package dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class Sql { private static final String DBDRIVER="org.gjt.mm.mysql.Driver"; private static final String URL="jdbc:mysql://localhost:3306/userinfo";//数据库连接字符串 private static final String NAME="root";//登录名 private static final String PASSWORD="111111";//密码 Connection conn = null; public void TheSqlConnection() { { //1.加载驱动 try { Class.forName(DBDRIVER); } catch (ClassNotFoundException e) { e.printStackTrace(); } try { conn = DriverManager.getConnection(URL, NAME, PASSWORD); } catch (SQLException e) { e.printStackTrace(); } //数据库打开后就要关闭 /*if(conn!=null) { try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); conn=null; } }*/ } } }
最近下载更多