close
一、建立 INSERT TABLE SQL
public static String getInsertSql(String cusId,String cusName,String cusAge,String cusAddress,String salary) {
return "INSERT INTO CUSTOMER (CUS_ID,CUS_NAME,CUS_AGE,CUS_ADDRESS,SALARY) " +
"VALUES ("+cusId+",'"+cusName+"',"+cusAge +",'"+ cusAddress+"',"+ salary+");";
}
二、程式
package com.sqlite.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertTableSQLiteJDBC {
public static String getInsertSql(String cusId,String cusName,String cusAge,String cusAddress,String salary) {
return "INSERT INTO CUSTOMER (CUS_ID,CUS_NAME,CUS_AGE,CUS_ADDRESS,SALARY) " +
"VALUES ("+cusId+",'"+cusName+"',"+cusAge +",'"+ cusAddress+"',"+ salary+");";
}
public static void main(String args[]) {
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:data/test.db");
c.setAutoCommit(false);
stmt = c.createStatement();
stmt.executeUpdate(getInsertSql("1","levin","23","新北市","2000.15"));
c.commit();
System.out.println("INSERT Table successfully.");
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
}finally{
try {
if(null != stmt){
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(null != c){
c.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
System.exit(0);
}
}
三、建立測試專案
參考:Java Using SQLite
四、執行程式
圖1
五、查看資料
參考:SQLite Manager For Firefox
圖2
五、相關文章
Java Using SQLite
SQLite CREATE TABLE Using Java
SQLite INSERT TABLE Using Java
SQLite SELECT TABLE Using Java
SQLite UPDATE TABLE Using Java
SQLite DELETE TABLE Using Java
其它文章
- 首頁
- JAVA教學目錄
- JSP教學目錄
- Apache教學目錄
- Google App Engine教學目錄
- JBoss教學目錄
- Android教學目錄
- Grails教學目錄
- SSH教學目錄
- Window教學目錄
- Linux教學目錄
- PHP教學目錄
- C教學/C++教學目錄
- jQuery教學目錄
- HTML5教學/CSS3教學目錄
- JavaScript教學目錄
- MySQL教學目錄
- Oracle教學目錄
- SQL Server教學/PostgreSQL教學/其它資料庫教學目錄
- Eclipse教學及開發相關工具教學目錄
- 程式開發基本資訊目錄
- 其它技術教學目錄
文章標籤
全站熱搜
留言列表