`mysql BaseDao基础语句`

tech2024-10-21  3

`mysql BaseDao基础语句` ```java public class BaseDao { static{ //加载驱动 try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static Connection getcon(){ Connection con =null; // 打开链接 try { con= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jsp","root","ccat"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return con; } public static void colse(Connection con,PreparedStatement pst,ResultSet rs){ //关闭引流 try { if(rs!=null){ rs.close(); } if(pst!=null){ pst.close(); } if(con!=null){ con.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { //测试mysql链接是否成功 System.out.println(getcon()); } }
最新回复(0)