haoningabc 发表于 2013-1-13 00:42:22

sqlite的helloworld

http://www.sqlite.org/download.html
下载所需

sqlitejdbc-v033-nested.jar放到classpath下
链接字符串jdbc:sqlite:haoningge.db
haoningge.db是当前目录下的haoningge.db文件,没有则新建
注意:如果在windows下,比如路径为C:/java/python/sqlite/haoningge.db
数据库连接时候,程序放在同一个盘下,用/java/python/sqlite/haoningge.db连接
或者jdbc:sqlite://c:/java/python/sqlite/haoningge.db

import java.sql.*; import org.sqlite.JDBC; public class TestSQLite{ public static void main(String[] args){ try{ Class.forName("org.sqlite.JDBC"); Connection conn =DriverManager.getConnection("jdbc:sqlite:jdbc:sqlite:/java/python/sqlite/haoningge.db"); Statement stat = conn.createStatement(); stat.executeUpdate("create table myfriend(name varchar(20), salary int);");stat.executeUpdate("insert into myfriend values('bestchenwu',4500);");stat.executeUpdate("insert into myfriend values('besttl',4500);"); stat.executeUpdate("insert into myfriend values('haoningge',15000);"); stat.executeUpdate("insert into myfriend values('davencool',12000);"); ResultSet rs = stat.executeQuery("select * from myfriend;");while(rs.next()){System.out.print("name = "+ rs.getString("name")+" ");System.out.println("salary = "+ rs.getString("salary"));} rs.close(); conn.close();}catch(Exception e ){ e.printStackTrace(); } } }}
已经存在的db文件可以用sqlitemanager打开,http://www.sqlitemanager.org/fr/installation/sqlitemanager/installation-de-sqlitemanager.html


---------------------------------
apt-get install sqlite
apt-get install sqlite3
命令行:
>sqlite3 haoningge.dbsqlite>.databasesqlite>.tablessqlite>.header onsqlite>select * from myfriendsqlite> .schemaCREATE TABLE myfriend(name varchar(20), salary int);sqlite> .schema myfriendCREATE TABLE myfriend(name varchar(20), salary int);sqlite> sqlite>.helpsqlite>.showsqlite>.exit
参考
http://wenku.baidu.com/view/639123c46137ee06eff918a5.html
-----------------------
可以直接用
sqlite3data.db ".tables"
sqlite3data.db "select * from auth_group"
sqlite3 -html data.db "select * from auth_group" >a.html

---------------------
sqlitemanager这个工具可以把数据显示成图
例如
http://www.sqlabs.com/sqlitemanager.php
在chart里输入
select id from auth_group limit 12;
选pie chart ,2D
http://www.sqlabs.com/images/sqlitemanager/detail4.png
可惜这个导不出来
据说可以结合excel导出来,
-----------
如果是ubuntu可以用
apt-get install sqlitebrowser
http://sqlitebrowser.sourceforge.net/
页: [1]
查看完整版本: sqlite的helloworld