In [1]:
%classpath add mvn org.xerial sqlite-jdbc 3.27.2.1
In [2]:
import collection.JavaConverters._
Out[2]:
In [3]:
import java.sql.DriverManager
val connection = DriverManager.getConnection("jdbc:sqlite:sample.db")
Out[3]:
In [4]:
val statement = connection.createStatement()
Out[4]:
In [5]:
statement.setQueryTimeout(30)
In [6]:
statement.executeUpdate("drop table if exists person")
Out[6]:
In [7]:
statement.executeUpdate("create table person (id integer, name string)")
Out[7]:
In [8]:
statement.executeUpdate("insert into person values(1, 'leo')")
Out[8]:
In [9]:
statement.executeUpdate("insert into person values(2, 'yui')")
Out[9]:
In [15]:
val results = statement.executeQuery("select * from person")
Out[15]:
In [16]:
while(results.next()){
println("name = " + results.getString("name"))
println("id = " + results.getInt("id"))
}
In [17]:
println(1)
In [ ]: