首页 > 代码库 > 数据库连接代码 (javaBean)

数据库连接代码 (javaBean)

数据库代码连接

public class DataCon {     private static final String Driver = "com.mysql.jdbc.Driver";//jar包驱动     private static final String url = "jdbc:mysql://localhost:3306/myhome";//数据库连接路径,数据库名     private static final String user = "root";//数据库用户名     private static final String password = "root";//数据库密码                     public Connection getConnction(){     Connection con = null;     try {     Class.forName(Driver);//引用驱动     con = DriverManager.getConnection(url, user, password);//数据库连接                     } catch (Exception e) {     e.printStackTrace();     }     return con;     }            //关闭数据库     public void closeAll(ResultSet rs, PreparedStatement ps, Connection con)     {     try {     rs.close();     ps.close();     con.close();     } catch (Exception e) {     e.printStackTrace();     }                             }}