zoukankan      html  css  js  c++  java
  • IDEA中使用Sqlite3

    去maven下载驱动包 ( jar包 )  下载地址:http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc/3.23.1

    打开IDEA

    创建一个class类

    package com.dao;
    import java.sql.*;
    
    public class DBHelp {
        //连接对象
        static Connection conn =null;
        //命令对象
        static Statement stmt=null;
        static PreparedStatement pstmt=null;
        //结果集
        static  ResultSet rs = null;
    
        public static void  open(){
            try {
                Class.forName("org.sqlite.JDBC");
           //我这里的数据库是 在 E盘里的MyDB文件夹下 conn = DriverManager.getConnection("jdbc:sqlite:E:\MyDB\iphone.db"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } public ResultSet getAll(String sql){ open(); try { stmt = conn.createStatement(); return rs = stmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } return null; } public int delete(String sql){ open(); try { stmt = conn.createStatement(); return stmt.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } return 0; } public int insert(String sql,Object[] in){ open(); try { pstmt =conn.prepareStatement(sql); for(int i=0;i<in.length;i++) pstmt.setObject(i+1,in[i]); return pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } return 0; } public int update(String sql,Object[] in){ open(); try { pstmt=conn.prepareStatement(sql); for(int i=0;i<in.length;i++){ pstmt.setObject(i+1,in[i]); } return pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } return 0; } public static void close(){ try { if(rs!=null) rs.close(); if(stmt!=null) stmt.close(); if(conn!=null) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }

    然后 开始你的测试吧。(♪(^∇^*))

  • 相关阅读:
    Java IO包装流如何关闭?
    Validator关于js,jq赋值不触发验证解决办法
    4 统计量&抽样分布
    3 概率的基本概念&离散型随机变量
    2 数据的概括性度量
    1 数据 & 图表
    Python 闭包
    一个自动修正数据时间和补全缺失数据的MapReduce程序
    MapReduce原理
    Hadoop MapReduce常用输入输出格式
  • 原文地址:https://www.cnblogs.com/oukele/p/9540773.html
Copyright © 2011-2022 走看看