irpas技术客

java 读取sqlite3_梦无痕123_java sqlite3

大大的周 7813

jar:sqlite-jdbc-3.7.2.jar

字典:汉字解释

package com.lago;

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

public class SqliteDB { ? ?? ? ? private static final String Class_Name = "org.sqlite.JDBC"; ? ? private static final String DB_URL = "jdbc:sqlite:D:\\py2\\WhatIsYourName-main\\data\\zidian.db3";

? ? public static void main(String args[]) { ? ? ? ? // load the sqlite-JDBC driver using the current class loader ? ? ? ? Connection connection = null; ? ? ? ? try { ? ? ? ? ? ? connection = createConnection(); ? ? ? ? ? ? func1(connection); ? ? ? ? ? ? System.out.println("Success!"); ? ? ? ? } ?catch (SQLException e) { ? ? ? ? ? ? System.err.println(e.getMessage()); ? ? ? ? } catch(Exception e) { ? ? ? ? ? ? e.printStackTrace(); ? ? ? ? } finally{ ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? if (connection != null) ? ? ? ? ? ? ? ? ? ? connection.close(); ? ? ? ? ? ? } catch (SQLException e) { ? ? ? ? ? ? ? ? // connection close failed. ? ? ? ? ? ? ? ? System.err.println(e); ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ?? ? ? // 创建Sqlite数据库连接 ? ? public static Connection createConnection() throws SQLException, ClassNotFoundException { ? ? ? ? Class.forName(Class_Name); ? ? ? ? System.out.println(Class_Name); ? ? ? ? return DriverManager.getConnection(DB_URL); ? ? }

? ? public static void func1(Connection connection) throws SQLException { ? ? ? ? Statement statement = connection.createStatement(); ? ? ? ? statement.setQueryTimeout(30); // set timeout to 30 sec. ? ? ? ? // 执行查询语句 ? ? ? ? ResultSet rs = statement.executeQuery("select * from WordDictionary"); ? ? ? ? int num =0; ? ? ? ?? ? ? ? ? while (rs.next()) { ? ? ? ? ? ? String col1 = rs.getString("Word"); ? ? ? ? ? ? String col2 = rs.getString("PinYin_1"); ? ? ? ? ? ? String col3 = rs.getString("Bushou"); ? ? ? ? ? ? String col4 = rs.getString("Wubi"); ? ? ? ? ? ? String col5 = rs.getString("bihua"); ? ? ? ? ? ? String col6 = rs.getString("Remark"); ? ? ? ? ? ? String col7 = rs.getString("content"); ? ? ? ? ? ? System.out.println("col1 = " + col1 + " ?col2 = " + col2 +"===="+col3+"===="+col4+"===="+col5+"===="+col6+"===="+col7); ? ? ? ? ? ? num++; ? ? ? ? } ? ? ?System.out.println(num); ? ? } }


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #JAVA #sqlite3 #comlagoimport