package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 数据库工具类
 * @author xujinnan
 *
 */
public class DataBaseUtil {

	//测试方法
	public static void main(String[] args) {
		try {
			Connection conn = getConnection();
			Statement stat = conn.createStatement();
			ResultSet rs = stat.executeQuery("select * from product;");// 查询数据
			while (rs.next()) {// 将查询到的数据打印出来
				System.out.print("name = " + rs.getString("name") + " ");// 列属性一
				System.out.println("productNo = " + rs.getString("product_no"));// 列属性二
			}
			rs.close();
			conn.close();// 结束数据库的连接
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取Connection的工具方法
	 * @return
	 */
	public static Connection getConnection(){
		// 连接SQLite的JDBC
		try {
			Class.forName("org.sqlite.JDBC");
			// 建立一个数据库名zieckey.db的连接,如果不存在就在当前目录下创建之
			Connection conn = DriverManager.getConnection("jdbc:sqlite:psims.db");
			return conn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
最近下载更多
lixieen  LV11 2023年8月3日
计算机暴龙战士  LV19 2022年11月19日
testuser1234567  LV24 2022年5月31日
1806795436  LV4 2022年2月18日
977903096  LV10 2021年12月24日
liuahm0813  LV4 2021年12月23日
wanglinddad  LV54 2021年12月14日
ajie2123  LV4 2021年12月14日
Demo1111  LV30 2021年12月12日
qsyqa0  LV6 2021年9月5日
最近浏览更多
FFF112233  LV8 3月28日
zhaoyahui234  LV6 3月22日
tll123456  LV1 3月15日
codeshare  LV3 1月3日
lshlsh 2023年12月25日
暂无贡献等级
一眼丁真  LV1 2023年12月16日
adfadfs 2023年12月10日
暂无贡献等级
李朝磊  LV18 2023年12月3日
LTPR66  LV1 2023年12月1日
云空城  LV1 2023年11月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友