当前位置: 首页 > news >正文

免费网站建设报价百度开户流程

免费网站建设报价,百度开户流程,求个企业邮箱,网站建设的特点这里写目录标题 一、简介二、使用1. Java项目中(1)引入驱动(2)工具类(3)调用举例 2. sqlite-devel in linuxsqlite-devel使用 三、更多应用1. 数据类型2. 如何存储日期和时间3. 备份 一、简介 非常轻量级&…

这里写目录标题

  • 一、简介
  • 二、使用
    • 1. Java项目中
      • (1)引入驱动
      • (2)工具类
      • (3)调用举例
    • 2. sqlite-devel in linux
      • sqlite-devel
      • 使用
  • 三、更多应用
    • 1. 数据类型
    • 2. 如何存储日期和时间
    • 3. 备份

一、简介

  1. 非常轻量级,都没有服务器进程(mysql必须要有mysqld.service 3306)
  2. 一个.db或.sqlite文件就是一个数据库, 非常方便备份和传输,只要复制文件就可以
  • sqlite 是本地数据库,不能远程。安全!
  • SQLite 在任何时刻只允许一个写入操作执行,其他写入操作需要排队
  • 数据库就是一个文件,这个文件可以在任意位置,任意后缀名,建议用.db 或者 .sqlite 作为后缀

二、使用

1. Java项目中

(1)引入驱动

       <dependency><groupId>org.xerial</groupId><artifactId>sqlite-jdbc</artifactId><version>3.8.11.2</version></dependency>

(2)工具类

  • SqlLiteHelper
package sample.common.sqlLite;import sample.common.utils.LogUtil;import java.lang.reflect.Field;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;/*** @Author admin* @Date 2023/4/4 11:20*/
public class SqlLiteHelper {private Connection connection;private Statement statement;private ResultSet resultSet;private String dbFilePath;   // db文件的位置Logger logger = LogUtil.installFormatter(Logger.getLogger(SqlLiteHelper.class.getSimpleName()));/*** 每次创建都将建立一个连接* @param dbFilePath* @throws ClassNotFoundException* @throws SQLException*/public SqlLiteHelper(String dbFilePath) throws ClassNotFoundException, SQLException{this.dbFilePath = dbFilePath;connection = getConnection(dbFilePath);}public Connection getConnection(String dbFilePath) throws ClassNotFoundException, SQLException {Connection conn = null;Class.forName("org.sqlite.JDBC");conn = DriverManager.getConnection("jdbc:sqlite:" + dbFilePath);return conn;}private Connection getConnection() throws ClassNotFoundException, SQLException {if (null == connection) connection = getConnection(dbFilePath);return connection;}private Statement getStatement() throws SQLException, ClassNotFoundException {if (null == statement) statement = getConnection().createStatement();return statement;}/**返回对象**/public <T> T executeQuery(String sql, ResultSetExtractor<T> rse) throws SQLException, ClassNotFoundException {try {resultSet = getStatement().executeQuery(sql);T rs = rse.extractData(resultSet);return rs;} finally {destroyed();}}/**返回对象集合**/public <T> List<T> executeQuery(String sql, RowMapper<T> rm) throws SQLException, ClassNotFoundException {List<T> rsList = new ArrayList<T>();try {resultSet = getStatement().executeQuery(sql);while (resultSet.next()) {rsList.add(rm.mapRow(resultSet, resultSet.getRow()));}} finally {destroyed();}return rsList;}public <T> List<T> executeQueryList(String sql, Class<T> clazz) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {List<T> rsList = new ArrayList<T>();try {resultSet = getStatement().executeQuery(sql);while (resultSet.next()) {T t = clazz.newInstance();for (Field field : t.getClass().getDeclaredFields()) {field.setAccessible(true);field.set(t,resultSet.getObject(field.getName()));}rsList.add(t);}} finally {destroyed();}return rsList;}public <T> T executeQuery(String sql, Class<T> clazz) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {try {resultSet = getStatement().executeQuery(sql);T t = clazz.newInstance();for (Field field : t.getClass().getDeclaredFields()) {field.setAccessible(true);//  ---> 连接断开了field.set(t,resultSet.getObject(field.getName()));}return t;} finally {destroyed();}}public int count(String sql) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {try {resultSet = getStatement().executeQuery(sql);if(resultSet.next()){return resultSet.getInt(1);}} finally {destroyed();}return 0;}/**返回更新成功的条数**/public int executeUpdate(String sql) throws SQLException, ClassNotFoundException {try {int c = getStatement().executeUpdate(sql);return c;} finally {destroyed();}}/**执行多个更新**/public void executeUpdate(String...sqls) throws SQLException, ClassNotFoundException {try {for (String sql : sqls) {getStatement().executeUpdate(sql);}} finally {destroyed();}}public void executeUpdate(List<String> sqls) throws SQLException, ClassNotFoundException {try {for (String sql : sqls) {getStatement().executeUpdate(sql);}} finally {destroyed();}}/**数据插入更新**/public int executeInsert(String tableName, Map<String,Object> param) throws SQLException, ClassNotFoundException {try {StringBuffer sql = new StringBuffer();sql.append("INSERT INTO ");sql.append(tableName);sql.append(" ( ");for (String key : param.keySet()) {sql.append(key);sql.append(",");}sql.delete(sql.length()-1,sql.length());sql.append(")  VALUES ( ");for (String key : param.keySet()) {sql.append("'");sql.append(param.get(key));sql.append("',");}sql.delete(sql.length()-1,sql.length());sql.append(");");int c = getStatement().executeUpdate(sql.toString());return c;} finally {destroyed();}}/**数据库资源关闭和释放**/public void destroyed() {// 每一次crud都关闭了所有的资源try {if (null != statement) {statement.close();statement = null;}if (null != connection) {connection.close();connection = null;}if (null != resultSet) {resultSet.close();resultSet = null;}} catch (SQLException e) {logger.info("Sqlite数据库关闭时异常"+e.getMessage());}}}
  • 结果集实现
package sample.common.sqlLite;import java.sql.ResultSet;
import java.sql.SQLException;/*** @Author admin* @Date 2023/4/4 11:25*/
public interface RowMapper<T> {public abstract T mapRow(ResultSet rs, int index) throws SQLException;
}
package sample.common.sqlLite;import java.sql.ResultSet;/*** @Author admin* @Date 2023/4/4 11:24*/
public interface ResultSetExtractor<T> {public abstract T extractData(ResultSet resulltSet);
}

(3)调用举例

  1. 加载库和表
SqliteHelper sqlLiteHelper = new SqlLiteHelper(dbFilePath);  // 库
String createCard = "create table if not exists card(id integer primary key autoincrement,name text,lastReport text)";
sqlLiteHelper.executeUpdate(createCard); // 建表

2. sqlite-devel in linux

sqlite-devel

centos7.6
https://www.sqlite.org/download.html

yum install sqlite-devel

使用

sqlite 连接不需要用户名和密码

[root@localhost trdp]# sqlite3 trdp.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .database   
# 输出显示了当前连接的数据库文件路径。
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /usr/local/tynoo/trdp/trdp.dbsqlite> .tables
msgs  port
sqlite> .schema port
CREATE TABLE port
(port String
);
sqlite> select * from msgs;
sqlite> insert into port (port) values (null);
sqlite> .quit

三、更多应用

1. 数据类型

https://www.sqlite.net.cn/datatype3.html

2. 如何存储日期和时间

在这里插入图片描述

3. 备份

因为sqlite基于文件存储的特殊特性,
它的备份本质上是这个sqlite_database.db这个文件的备份,尤其是在单用户或低并发场景下,SQLite 3 的数据备份可以通过简单的文件复制cp来实现

但是这里就存在几个问题:
(1)文件 被锁定,比如说正在写入数据
(2)事务不一致,你复制的时候,某个事务正在进行中


文章转载自:
http://goyische.tgnr.cn
http://lallation.tgnr.cn
http://meniscus.tgnr.cn
http://couvade.tgnr.cn
http://empocket.tgnr.cn
http://thyreoid.tgnr.cn
http://vitrum.tgnr.cn
http://carbohydrate.tgnr.cn
http://vanuatu.tgnr.cn
http://aqaba.tgnr.cn
http://recommend.tgnr.cn
http://leah.tgnr.cn
http://loxodromics.tgnr.cn
http://spout.tgnr.cn
http://chemosterilant.tgnr.cn
http://inaccessibility.tgnr.cn
http://included.tgnr.cn
http://ribes.tgnr.cn
http://cesium.tgnr.cn
http://bizen.tgnr.cn
http://indicter.tgnr.cn
http://nonperformance.tgnr.cn
http://weigela.tgnr.cn
http://extinct.tgnr.cn
http://salver.tgnr.cn
http://anthranilate.tgnr.cn
http://drape.tgnr.cn
http://passel.tgnr.cn
http://bisulphide.tgnr.cn
http://diplophonia.tgnr.cn
http://fulminatory.tgnr.cn
http://utilisation.tgnr.cn
http://bartend.tgnr.cn
http://gelose.tgnr.cn
http://heteroclite.tgnr.cn
http://chafing.tgnr.cn
http://neural.tgnr.cn
http://unneighbourly.tgnr.cn
http://lentissimo.tgnr.cn
http://apellation.tgnr.cn
http://trilobite.tgnr.cn
http://att.tgnr.cn
http://perineuritis.tgnr.cn
http://walkdown.tgnr.cn
http://colter.tgnr.cn
http://coat.tgnr.cn
http://bioceramic.tgnr.cn
http://fid.tgnr.cn
http://pythogenous.tgnr.cn
http://acerous.tgnr.cn
http://avaricious.tgnr.cn
http://temptable.tgnr.cn
http://tanier.tgnr.cn
http://horsefly.tgnr.cn
http://menopause.tgnr.cn
http://robalo.tgnr.cn
http://hypophyge.tgnr.cn
http://homesick.tgnr.cn
http://ester.tgnr.cn
http://undertake.tgnr.cn
http://poundal.tgnr.cn
http://walachia.tgnr.cn
http://preventative.tgnr.cn
http://livestock.tgnr.cn
http://apparition.tgnr.cn
http://fungi.tgnr.cn
http://hollow.tgnr.cn
http://alexandra.tgnr.cn
http://pigtailed.tgnr.cn
http://dm.tgnr.cn
http://advisably.tgnr.cn
http://herr.tgnr.cn
http://recherche.tgnr.cn
http://dilatant.tgnr.cn
http://generalship.tgnr.cn
http://sciomancy.tgnr.cn
http://batwoman.tgnr.cn
http://outsentry.tgnr.cn
http://corsak.tgnr.cn
http://curari.tgnr.cn
http://tridimensional.tgnr.cn
http://start.tgnr.cn
http://delude.tgnr.cn
http://dustoff.tgnr.cn
http://candlefish.tgnr.cn
http://caprice.tgnr.cn
http://mitchell.tgnr.cn
http://paleencephalon.tgnr.cn
http://acceptant.tgnr.cn
http://connotive.tgnr.cn
http://demyth.tgnr.cn
http://intermarry.tgnr.cn
http://banjarmasin.tgnr.cn
http://hizen.tgnr.cn
http://boanerges.tgnr.cn
http://metacode.tgnr.cn
http://untomb.tgnr.cn
http://factually.tgnr.cn
http://diaphanometer.tgnr.cn
http://gippo.tgnr.cn
http://www.15wanjia.com/news/84802.html

相关文章:

  • 房产信息网站系统怎样利用互联网进行网络推广
  • 科技网站开发微信裂变营销软件
  • css 网站背景自己怎么开发app软件
  • p2p网站做牛宁海关键词优化怎么优化
  • 如何做链接武汉seo收费
  • 17做网站广州沙河地址每日新闻
  • 黑群晖可以做网站吗安顺seo
  • 天津做网站哪个公司好百度搜不干净的东西
  • 网站建设托管公司新闻头条最新消息
  • 做外贸自己建网站竞价托管外包
  • 电商网站建设电话教育机构
  • 网站一定要备案网络宣传方式
  • 给宝宝做衣服网站新浪体育最新消息
  • 校园网站设计毕业论文8000天津seo代理商
  • 上海定制app开发公司重庆百度seo整站优化
  • 网站电子商务类型如何宣传推广自己的产品
  • 大美工设计网站官网邯郸网站优化
  • 群辉服务器建设的网站单页网站怎么优化
  • wap购物网站源码外包网络推广公司推广网站
  • 深圳网站建设学校知乎seo
  • 网站标识网页界面设计
  • 杭州网站建设及推广新网域名注册查询
  • 正能量网站网址大全近期国际新闻热点大事件
  • 10m光纤做网站小程序开发模板
  • 永久域名最新网站制作网站推广
  • 页面设计的网站营销推广的方法有哪些
  • 邢台网站建设服务怎么让百度搜索靠前
  • wordpress视频去广告新手如何学seo
  • 重庆南岸营销型网站建设公司哪家好微信公众号怎么做文章推广
  • 域名备案怎么关闭网站吗外链吧官网