java????????
???????????? ???????[ 2017/4/19 11:35:56 ] ????????Java ?????
?????????????????SQLite?????
?????????database????????????????????洢????????????????????????????г??????????????????????洢??????????????????????????????????????
?????????????
???????????????????????????????????????????????????????????DBMS???????????
??????????????????????????Oracle??DB2??SQLServer??MySQL??
????DBMS???????????????????
????????????????????????????????????飩?????????????????????????????????????
????????????????SQL?????????????????????o?????????????
????SQLite???????????????????????????????????????????
????????????????
????????????SQL???
??????????????????
????SQLite?????????????????????????????κ??????????SQLite?????????????ж??
?????????????NULL?????INTEGER??????????Σ?????Java?е?Int???REAL???????????????Java?е?float/double?? TEXT/VARCHAR??????????????Java?е?String??BLOB???????????????Java?е?byte???顣
??????????????洢????????Щ?????????????????????????????>20??
????CREATE TEBLE ?????????y??????ε?????????????????????????????????????????????????????????????????
??????????NOT NULL ???
????UNIQUE PRIMARY KEY ????
????FORFIGN KEY ????? CHECK ??????? DEFAULT???
???????????
????create table tablename(col1 type1[not null][primarykey]??col2 type2…)
????create table tablename(????)(col1(????) type1??????????????[not null]?????????[primarykey]??col2 type2…)
????Insert???
????insert into student (name??cid??gender??age??score)value(‘tom’??1??1??20??80.2);
????Update???
????update student set name=’jack’ where name=’tom’;
????Select???
??????????select * from ????;
???????ID?1???????select * from student where id=1;
????*????????????????eg:
????select id??name??score from student;???id??name ??score ?????????
????Delete???
?????????????????
????delete from student where score<60;
????drop table ????????????
?????????????飬?????????
????select * from student1 a??employee b where(a.[id]=b.[id]) and( a.name=’song’)
????????JDBC API??Java????????????
????JDBC ?????????????SQL????API??????????????????????????????????Java?????д????????
????JDBC???????4???????
????1??JDBC——ODBC??
?????????е?JDBC?????????ODBC?????ú??????????????????????
????2??????API??????
????????????????????????????????????????????????????????а?????Java????
????3??????Э????????
????????????????????API??????????JDBC????????????????Socket?????÷?????????м?????????????????????????????API???á?
????4??????Э?飺
???????Socket??????????????????????
????JDBC???????£? ?????????????????????????SQL???????????
???????????????????
????Java????????????????????????????????connection???????
????????????????????????????
????Class.forName(“org.sqlite.JDBC”);
????????????????????
????Connection conn = DriverManager.getConnection(“jdbc:sqlite:d:/stu.db”??”“??”“);
???????????????????Э??url??????????D???μ?stu?????????????????????????????
?????????????????SQL???
????JDBC???????????????????????SQL???
????connection????е????????????????????Щ??????
????Statement????Connection?????createStatement????????Statement???????????SQL???
????PreparedStatement????prepareStatement????????PreparedStatement????????????????????????SQL???
????CallableStatement: ??prepareCall????????CallableStatement???????????SQL?洢?????
????????????
?????????????????????????????????????????????????????????????????
??????????????????????????????????????
????????????? ???????????ResultSet
????1??ResultSet??next()?????????????м??????ж??????????????????
????2??ResultSet?е?getxxx()?????????????е???????????????
????eg??
????package com.tian.sqlite;
????import java.sql.Connection;
????import java.sql.DriverManager;
????import java.sql.PreparedStatement;
????import java.sql.ResultSet;
????import java.sql.SQLException;
????import java.sql.Statement;
????import java.util.ArrayList;
????import java.util.List;
????public class SqliteDemo {
????public static void main(String[] args) {
????List list = fetchData();
????for(Employee e:list){
????System.out.println(e);
????}
????Employee employee = login("tian"??"1234");
????if(employee!=null){
????System.out.println("??????"+" ?????"+employee.getName());
????}else{
????System.out.println("??????"+" ?????μ????");
????}
????Employee employee1 = login("song"??"5678");
????if(employee1!=null){
????System.out.println("??????"+" ?????"+employee1.getName());
????}else{
????System.out.println("??????"+" ?????μ????");
????}
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11