DbUtil和Result接口

来源:互联网 发布:瑟尔效应 知乎 编辑:程序博客网 时间:2024/05/18 20:50
public class DbUtil {/*private Connection conn;private Statement sta;*/private static String url="jdbc:mysql://localhost:3306/";private static String user="root";private static String password="";static{try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public static Connection getConnection(){ Connection conn = null;try { conn= DriverManager.getConnection(url, user, password);return conn;} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return conn;}public static void close(Connection conn,Statement stmt){if (stmt!=null) {try {stmt.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if (conn!=null) {try {stmt.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}






原创粉丝点击