DB的封装
Posted 彩屏黑白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DB的封装相关的知识,希望对你有一定的参考价值。
public class DB { public static Connection getConn() { Connection conn=null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/bbs", "root", "root"); } catch (Exception e) { e.printStackTrace(); } return conn; } public static Statement getStatement(Connection conn) { Statement stmt=null; try { stmt=conn.createStatement(); } catch (SQLException e) { e.printStackTrace(); } return stmt; } public static ResultSet executeQuery(Statement stmt,String sql) { ResultSet rs=null; try { rs=stmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } return rs; } public static void close(Connection conn) { if(conn != null) try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } public static void close(Statement stmt) { if(stmt != null) try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } public static void close(ResultSet rs) { if(rs != null) try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } }
以上是关于DB的封装的主要内容,如果未能解决你的问题,请参考以下文章
VSCode自定义代码片段14——Vue的axios网络请求封装
Android 逆向使用 DB Browser 查看并修改 SQLite 数据库 ( 从 Android 应用数据目录中拷贝数据库文件 | 使用 DB Browser 工具查看数据块文件 )(代码片段
Android 逆向使用 DB Browser 查看并修改 SQLite 数据库 ( 从 Android 应用数据目录中拷贝数据库文件 | 使用 DB Browser 工具查看数据块文件 )(代码片段