SQLite and JAVA

Monday, 29 June 2009

I may edit this post again after publish. A sample Java code  with SQLite.

package package;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class MyClass {
private Connection con;
private Statement stat;
private ResultSet rs;
private PreparedStatement pre;
public static void main(String[] args) {
try{
Class.forName("org.sqlite.JDBC");
Connection con= DriverManager.getConnection("jdbc:sqlite:mydata.db");
Statement stat= con.createStatement();
// stat.execute("CREATE TABLE mydata( Name VARCHAR(13) PRIMARY KEY, Address VARCHAR(50) NOT NULL);");
PreparedStatement pre=con.prepareStatement("insert into mydata values(?,?);");
pre.setString(1, "Aruz");
pre.setString(2, "Center of the World");
pre.addBatch();
con.setAutoCommit(false);
pre.executeBatch();
ResultSet rs= stat.executeQuery("select * from stok;");
while(rs.next()){
System.out.println("Name : "+ rs.getString("Name"));
System.out.println("Address : "+ rs.getString("Address"));
}
rs.close();
con.close();
}
catch(Exception e){
System.out.println("Error : "+ e);
}
}
}

And this is the output:
Name : Aruz
Address : Center of the World


Comments

  1. Thanks for the mention. The article itself shows that you put a great deal of care into your work,
    Thanks for sharing all these links and informative stuff.

    Posted by certification | 20 July 2009 08:50
  2. You may be interested in http://sqljet.com/ – pure Java implentation of SQLite. Does not support SQL in queries yet though.

    Posted by Alex | 11 August 2009 02:44
Leave a comment
Name(required)
Mail (will not be publishing) (required)
Website

  • time time time…
  • Recent Comments

  • Lütfü Hoca

  • Roll

  • Ads