10 Replies - 3375 Views - Last Post: 16 April 2011 - 06:02 AM Rate Topic: -----

#1 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

SQLite + java

Posted 15 April 2011 - 04:16 PM

Hello,
I want to use SQLite database in my project to store some data, but how to make it all work? :dozingoff:
I tried to find some tutorial, but without any success. Is there anybody, who would be so kind and tell me the steps how to create working SQLite database in my project? Thanks

edit: I don't need any code, which shows how to save some data in SQLite...I don't even know, how to add library with SQLite, install JDBC etc. :/

This post has been edited by Dworza: 15 April 2011 - 04:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: SQLite + java

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: SQLite + java

Posted 15 April 2011 - 04:27 PM

Check out this tutorial. :)
Was This Post Helpful? 1
  • +
  • -

#3 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

Re: SQLite + java

Posted 15 April 2011 - 08:14 PM

So if I understood it well, I only use JDBC API and I don't care what database I use? When I want to save on HDD SQLite db, I use the same command as if I want to save MySQL database?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: SQLite + java

Posted 15 April 2011 - 08:18 PM

As long as you have the appropriate drivers and use the correct SQL syntax for the specific database engine, you can simply use the JDBC API, and you will be good.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: SQLite + java

Posted 15 April 2011 - 08:20 PM

SQL is SQL it is a standard
few differences especially for the autoincrement feature but basically it is the same
Was This Post Helpful? 0
  • +
  • -

#6 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

Re: SQLite + java

Posted 15 April 2011 - 08:40 PM

View Postpbl, on 15 April 2011 - 08:20 PM, said:

SQL is SQL it is a standard
few differences especially for the autoincrement feature but basically it is the same


Hmm..but I know, how to save something into the database, using SQL. I don't know, how to save that whole database on the HDD :-S ...
Maybe my questions sounds stupid, but I really haven't worked with databases since now. :dontgetit:
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: SQLite + java

Posted 15 April 2011 - 08:42 PM

View Postpbl, on 15 April 2011 - 11:20 PM, said:

SQL is SQL it is a standard
few differences especially for the autoincrement feature but basically it is the same

Not a lot of the database engines adhere to standards entirely. A basic SELECT or INSERT statement might be the same for multiple databases, but more complex SQL features probably won't be. Plus, each vendor has their own extras that do not adhere to standards.

View PostDworza, on 15 April 2011 - 11:40 PM, said:

View Postpbl, on 15 April 2011 - 08:20 PM, said:

SQL is SQL it is a standard
few differences especially for the autoincrement feature but basically it is the same


Hmm..but I know, how to save something into the database, using SQL. I don't know, how to save that whole database on the HDD :-S ...
Maybe my questions sounds stupid, but I really haven't worked with databases since now. :dontgetit:

The SQL engine is a piece of software. You can download SQLite from here.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: SQLite + java

Posted 15 April 2011 - 08:43 PM

View PostDworza, on 15 April 2011 - 10:40 PM, said:

I don't know, how to save that whole database on the HDD :-S ...

The major concept behind database in that when the commit is done and return success, everything is saved on disk. No need to save anything by yourself on disk.
Was This Post Helpful? 0
  • +
  • -

#9 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

Re: SQLite + java

Posted 15 April 2011 - 08:55 PM

@macosxnerd101 : I've already downloaded it and use it, nevertheless thanks :)
@pbl : But I use it on my non client/server application...I just want to store some structured data on my disk, to be able to load them when the application starts next time. If it saves the database somewhere, where then? For example some code from some tutorial


Class.forName("org.sqlite.JDBC");
 Connection conn = DriverManager.getConnection("jdbc:sqlite:Vinit");
 Statement stat = conn.createStatement();
 stat.executeUpdate("drop table if exists school;");
 stat.executeUpdate("create table school (name, state);");
 PreparedStatement prep = conn.prepareStatement(
 "insert into school values (?, ?);");

 prep.setString(1, "UTD");
 prep.setString(2, "texas");
 prep.addBatch();
 prep.setString(1, "USC");
 prep.setString(2, "california");
 prep.addBatch();
 prep.setString(1, "MIT");
 prep.setString(2, "massachusetts");
 prep.addBatch();

 conn.setAutoCommit(false);
 prep.executeBatch();
 conn.setAutoCommit(true);

 ResultSet rs = stat.executeQuery("select * from school;");
 while (rs.next()) {
 System.out.print("Name of School = " + rs.getString("name") + " ");
 System.out.println("state = " + rs.getString("state"));
 }
 rs.close();
 conn.close();
 }




Where then is saved this database and how is it named?
Was This Post Helpful? 0
  • +
  • -

#10 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: SQLite + java

Posted 16 April 2011 - 02:08 AM

Well I think the database is saved in folder where is found your application. The file will be called Vinit. For more information about this you can find here: http://en.wikibooks....Lite/Connecting
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: SQLite + java

Posted 16 April 2011 - 06:02 AM

View PostDworza, on 15 April 2011 - 10:55 PM, said:

@pbl : I just want to store some structured data on my disk, to be able to load them when the application starts next time. If it saves the database somewhere, where then? For example some code from some tutorial


Sure that if you execute

stat.executeUpdate("drop table if exists school;");

it will delete the table (from disk) every time you start your application

But if you run your application AS IT IS and later on run

Class.forName("org.sqlite.JDBC");
 Connection conn = DriverManager.getConnection("jdbc:sqlite:Vinit");
 Statement stat = conn.createStatement();

 ResultSet rs = stat.executeQuery("select * from school;");
 while (rs.next()) {
 System.out.print("Name of School = " + rs.getString("name") + " ");
 System.out.println("state = " + rs.getString("state"));
 }
 rs.close();
 conn.close();
 }



It should list your schools registered in the database by the execution of the previous program.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1