BowerStudios.com

  • My Lab
  • Family
  • Friends
  • Professional
  • About
Home

sqlite and groovy walkthrough

daniel —Tue, 06/29/2010 - 8:58am

  • SQL
  • Groovy

Prereqs: sqlite3, groovy installed

note about sqlite and ubuntu:
There are at least 2 versions of sqlite in the repo. The sqlite package will not be able to read the db below. You'll need to install the sqlite3 package instead. You'll get a message about the db being encrypted or unreadable if you use just sqlite
$ sudo apt-get install sqlite3

If you are using gradle to manage your dependencies, then add this dependency to your build.gradle:
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.6.16'

An example groovy class using sqlite:
class PersistStatistic {
String dbLocation = "jdbc:sqlite:/pathToTestdb/testdb.db"
String dbDriver = "org.sqlite.JDBC"
def getDb(){
return groovy.sql.Sql.newInstance(dbLocation, dbDriver)
}
void insert(String url){
def sql = getDb()
sql.execute("insert into myTable(colname1, colname2) values(?, ?)", [url, new Date()])
}
void printContents(){
def sql = getDb()
sql.rows("select * from myTable order by date desc").each{
println(it)
}
}
}

To view the database:
use the printContents method above (change the sql statement appropriately), or
run sqlite at the command line:
* sqlite3 test.db
* run your sql statements to query the database
* .exit to exit sqlite3

Some links of use:
Sqlite home
Sqlite commands
Xerial sqlite jdbc driver
A nice groovy with sqlite walkthrough

  • Log in to post comments

Navigation

  • Search
  • Recent content
  • Contact Me
  • Mail
  • Pass Hasher
  • Bower Studios Admin

Quotes

daniel —Thu, 07/14/2016 - 5:49pm

A chronic disposition to inquiry deprives domestic felines of vital qualities

—

Anon

  • Log in to post comments
  • daniel's quotes

Popular content

Last viewed:

  • Port already in use error when trying to shutdown Apache Tomcat with JMX monitoring enabled
  • Ownership & Permissions Guide
  • Rdoc is not really all that good, yard seems to be a pleasant alternative
  • Quotes 762
  • Full Outer Join Vs Cross Join (Cartesian Product)

Copyright 2018 Daniel Bower
  • My Lab
  • Family
  • Friends
  • Professional
  • About