在Java下连接SQLite数据库
更新时间:2024-01-15 16:36:01 阅读量: 教育文库 文档下载
- JAVA连接sql推荐度:
- 相关推荐
一、下载SQLite数据库的JDBC:http://www.zentus.com/sqlitejdbc/ 二、将下载到的包解压后得到jar包放到%JAVA_HOME%\\lib下,并且将其添加到ClassPath系统环境变量中。一定要保证在类路径ClassPath中有该jar包,并且保证在JAVA库路径JAVA Library Path中有本地库Native Library(\\workspace\\\应用\下最好也要加入该jar包)。\作为JDBC的驱动程序类名。连接JDBC的URL格式为jdbc:sqlite:/path。这里的path为指定到SQLite数据库文件的路径,例如: jdbc:sqlite://dirA/dirB/dbfile
jdbc:sqlite://DRIVE:/dirA/dirB/dbfile
jdbc:sqlite://COMPUTERNAME/shareA/dirB/dbfile 三、下面是使用SQLite的两段代码以供参考: 代码段1:
1 import java.sql.*; 2 import org.sqlite.JDBC; 3
4 public class SQLiteTest {
5 public static void main(String[] args) { 6 try {
7 // The SQLite (3.3.8) Database File
8 // This database has one table (pmp_countries) with 3 columns (country_id, country_code, country_name)
9 // It has like 237 records of all the countries I could think of. 10 String fileName = \11 // Driver to Use
12 // http://www.zentus.com/sqlitejdbc/index.html 13 Class.forName(\
14 // Create Connection Object to SQLite Database
15 // If you want to only create a database in memory, exclude the +fileName
16 Connection conn = DriverManager.getConnection(\eName);
17 // Create a Statement object for the database connection, dunno what this stuff does though.
18 Statement stmt = conn.createStatement(); 19 // Create a result set object for the statement
20 ResultSet rs = stmt.executeQuery(\
s ORDER BY country_name ASC\
21 // Iterate the result set, printing each column
22 // if the column was an int, we could do rs.getInt(column name here) as well, etc.
23 while (rs.next()) {
24 String id = rs.getString(\// Column 1 25 String code = rs.getString(\// Column 2 26 String name = rs.getString(\// Column 3 27 System.out.println(\e); 28
29 }
30 // Close the connection 31 conn.close(); 32 }
33 catch (Exception e) {
34 // Print some generic debug info 35 System.out.println(e.getMessage()); 36 System.out.println(e.toString()); 37 } 38 } 39 }
正在阅读:
在Java下连接SQLite数据库01-15
7.2.1三角形的外角(教学设计)07-12
2012年苏教版国标本六下总复习资料集锦11-14
《世界海洋表层洋流的分布》教学设计03-25
2017年最新制度大全公司人力行政部制度汇编 - 图文06-29
泌尿系统感染指南 简化版04-08
惠普绘图仪HP800HP500HP510更换皮带完整步骤01-17
习精讲基础知识导学核心要点突破高考命题视角第2课时 君主专制政06-17
知识竞赛题目10-21
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 连接
- 数据库
- SQLite
- Java
- 科学三年级下册把液体倒进水里教学设计
- 商务礼仪教学大纲
- 2015-2016学年度高三生物第一轮复习计划
- 欧氏族谱资料
- 桩基缺陷的成因及处理
- 综合智商测试二
- 牛津译林版英语4下unit2
- 二、2014年AAA级安全文明标准化工地 - 图文
- 脾胃系疾病试题题库
- 公司近三年财务报表分析报告
- C300 EPON 中兴开局初学者配置手册最新
- 中南大学2008年推荐免试研究生公示
- 煤矿高压整定计算
- 2017届云南省昆明市第一中学新课标高三月考卷(五)英语试题
- 数值分析第五次实验报告
- WCA-D02 WCA Audit Document Checklist-with BP - EnglishChinese - 25 Nov 2014 Iss 05
- 土木工程概论简答题论述题大全及答案
- 营销工作未来发展方向展望及市场部角色定位
- 2015年度吴江华俊纺织有限公司销售收入与资产数据报告 - 图文
- 高中英语阅读课公开课教案一等奖 - 图文