Jimsql: 纯Java的文本数据库实现
Posted 麒思妙想
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jimsql: 纯Java的文本数据库实现相关的知识,希望对你有一定的参考价值。
前面两篇文章介绍了如何自定义jdbc,以及实现解析,今天我们来介绍这个项目的主体JimSQL
What is Jim
JimSql = Jim Isn’t mysql. Jim is a filesystem database system implemention use Java.
Useage
use docker-compose
to start a server
version: '3'
services:
jimsql:
privileged: true
image: dafei1288/jimsql_server:1.0.0
ports:
- "8821:8821"
- "8825:8825"
# volumes:
# - "./data:/jimsql/data"
environment:
# JAVA_OPTS: -agentlib:jdwp=transport=dt_socket,address=*:8825,server=y,suspend=n
JAVA_ARGS: 8821 0.0.0.0 /jimsql/data
Use snapshot repository
<repositories>
<repository>
<id>jim</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
Then use jdbc to connect
<dependency>
<groupId>com.dafei1288</groupId>
<artifactId>jdbc</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class TestServer
public static void main(String[] args) throws Exception
Class.forName("com.dafei1288.jimsql.jdbc.JqDriver");
Connection conn = DriverManager.getConnection("jdbc:jimsql://localhost:8821/test");
System.out.println(conn);
Statement statement = conn.createStatement();
System.out.println(statement);
String sql = "select id,name from user";
ResultSet resultSet = statement.executeQuery(sql);
System.out.println(sql);
System.out.println(resultSet);
while(resultSet.next())
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
List<String> colNames = new ArrayList<>();
for(int i=0;i<resultSetMetaData.getColumnCount();i++)
String colName = resultSetMetaData.getColumnLabel(i);
System.out.println(colName+" => "+resultSet.getString(colName));
System.out.println();
仓库地址 https://github.com/dafei1288/jimsql
欢迎大家fork、star , 目前只实现了简单查询,后续会继续添加 ddl,dml,dcl等特性
以上是关于Jimsql: 纯Java的文本数据库实现的主要内容,如果未能解决你的问题,请参考以下文章