SQLite jdbc 单例
来源:互联网 发布:去蓝光软件 编辑:程序博客网 时间:2024/06/05 17:12
package com.tsing.hua.DB;import java.sql.*;public class DB { public static final String Uri = "jdbc:sqlite:"; public static final String DataBase = "D:\\bbs.db";//数据库所在路径 public static final String ClassName = "org.sqlite.JDBC"; private static String URL = DB.Uri + DB.DataBase; private static Connection con = null; static { try { Class.forName(DB.ClassName); } catch (ClassNotFoundException e) { e.printStackTrace(); } } private DB() { System.out.println("private DB()..."); } public static Connection getConnection() { try { if (con == null) { con = DriverManager.getConnection(URL); } else { return con; } } catch (SQLException e) { e.printStackTrace(); return null; } return con; } public static void main(String[] args) { System.out.println(DB.getConnection()); con = DB.getConnection(); String sql = "select * from users"; try { PreparedStatement ps = con.prepareStatement(sql); ResultSet rs = ps.executeQuery(); for( ; rs.next() ; ) { int id = rs.getInt("uid");; String Name = rs.getString("name");; String Password = rs.getString("password");; System.out.println( " Users : id " + id); System.out.println( " Users : Name " + Name); System.out.println( " Users : Password " + Password); } } catch (Exception e) { e.printStackTrace(); } }
阅读全文
0 0
- SQLite jdbc 单例
- sqlite单例封装
- jdbc 单例
- jdbc&sqlite
- 健壮的JDBC单例
- 数据储存之SQLite(单例模式)
- SQLite JDBC Demo
- Sqlite JDBC 驱动示例
- SQLite JDBC 使用例子
- SQLite JDBC Driver
- JDBC连接数据库(单例设计模式)
- JDBC单例模式连接数据库方式
- JDBC连接(单例模式)
- jdbc工具类(单例模式)
- JDBC 连接数据库之单例模式
- Oracle jdbc 连接代码 单例
- SQLServer jdbc 连接代码 单例
- jdbc设计模式之单例模式
- 汉诺塔1
- ActiveMQ消息队列
- java基础第四讲JavaScript详解
- 汉诺塔2
- vue-router传参数(get和post方式)
- SQLite jdbc 单例
- IDEA错误:Cannot start compilation: the output path is not specified for module "Test". (转)
- 汉诺塔3
- Python学习之Numpy
- 深入JVM内核—原理与优化之六类加载器
- 12、Oracle的子查询
- 汉诺塔4
- 机器学习基石-05-3-Effective Number of Hypotheses
- union