Scaladbc

Update

Scala DBC2 seems to be in a state of orphanage.

There are newer attempts in this space, such as, scala-query and orbroker, which are likely to give you better mileage.

Scala Data base connector version 2

The DBC library comes packaged along with Scala (Look under $(scala-distribution)/src/).

There's a newer, unreleased, version called DBC2 available here. But it appears to be unmaintained.

The download available as an attachment to this page is a simple fix to the above, to get it in a working shape.

Compilation

The source can be built with SBT

Demo

See the file demo/demo.scala inside the package. It shows how to create, update and query a Derby database (requires Apache Derby to be in the class path).

Acknowledgement

The original authors did all the work. I just fixed some typos and stuff.


Why connection was closed?
rakuto (guest) 1232889830|%e %b %Y, %H:%M %Z|agohover

Try to CRUD operation using dbc2 package, but couldn't execute queries because scala.dbc2.exception.ClosedException was thrown.
How do I execute some queries?

import scala.dbc2.exception._

import java.sql._
import java.net.URI
import scala.dbc2.Database
import scala.dbc2.ShortSyntax._
import scala.dbc2.statement.AnyValueDef._
import scala.dbc2.statement.Relation
import scala.dbc2.statement.Status
import scala.dbc2.vendor.MySQL

object Demo extends Application {
    def printResults(res: dbc2.result.Relation) {
        for(val i <- res) {
            for(val f <- i.fields) {
                print("\t" + f.content.sqlString) 
            } 
            println()
        } 
    }

    val vendor:scala.dbc2.Vendor = scala.dbc2.vendor.MySQL(new URI("jdbc:mysql://localhost:3306/scala_test"), "mysql", "mysql")
    var db = new Database(vendor)

    // crate test DB
    try {
        var stmt = create table 'people columns('id integer primary key, 'name character varying(255))
        db.executeStatement(stmt.parse)
        println("Success")
    } catch {
        case e:Exception => println("table `people` already created")
    }

    // truncate a table
    var stmt = delete from 'people
    db.executeStatement(stmt.parse)

    // insert data
    val people = List((1, "Martin Odersky"), (2, "Guid van Rossam"))
    people.foreach {
        person => 
            var stmt2 = insert into 'people columns('id, 'name) values((person._1, person._2))
            // XXX: Failed because scala.dbc2.exception.ClosedException exception was thrown
            db.executeStatement(stmt2.parse)
    }

    var stmt3 = select(*) from('people)
    printResults(db.executeStatement(stmt3.parse))
}

Best regards.

unfold Why connection was closed? by rakuto (guest), 1232889830|%e %b %Y, %H:%M %Z|agohover
Re: Why connection was closed?
hrjhrj 1232965490|%e %b %Y, %H:%M %Z|agohover

Hi rakuto,

I am not well versed with the scala DBC2 package. I just brought it to a state where it compiled. The run-time behaviour is a little difficult to understand.

Looking at the source code, it seems like a call to Vendor.closeConnection happens after every statement is executed. It's not clear to me how it is re-opened again.

I advise you ask on the scala mailing list for support.

Cheers,
HRJ

unfold Re: Why connection was closed? by hrjhrj, 1232965490|%e %b %Y, %H:%M %Z|agohover
Re: Why connection was closed?
Sailaja (guest) 1249538775|%e %b %Y, %H:%M %Z|agohover

Hi,
I am also facing the same problem . I have searched for this on google no result. Is any solution for this problem….

Thanks in advance '
Sailaja.

unfold Re: Why connection was closed? by Sailaja (guest), 1249538775|%e %b %Y, %H:%M %Z|agohover
Re: Why connection was closed?
hrjhrj 1249620919|%e %b %Y, %H:%M %Z|agohover

I have added an update to the top of the page.

Please check out the other projects llisted there which are more likely to be stable.

unfold Re: Why connection was closed? by hrjhrj, 1249620919|%e %b %Y, %H:%M %Z|agohover
Help to compile DBC2
Santi (guest) 1252322395|%e %b %Y, %H:%M %Z|agohover

Hi HRJ,
I am new to this word, scala and dbc.
I need bdc2 but dont know how to build with SBT package.
¿can you show me to configuration for do it?
Thanks very much

What about dbc2/dbc3 in Scala 2.8.
Will be included?
Where is the api doc for these libraries?
Thank very much

unfold Help to compile DBC2 by Santi (guest), 1252322395|%e %b %Y, %H:%M %Z|agohover
How to Extract table values
mansurmansur 1255253761|%e %b %Y, %H:%M %Z|agohover

I am using scala lift . Also i using mysql to retrive the table value .

My doubt is ,

My query is —>val stmt4 = select ('id,'name) from('category) where 'name <>("'Contact'") and 'name <>("'Faq'")
printResults(db.executeStatement(stmt4.parse))

I want to display a id and name value .

def printResults(res: dbc2.result.Relation) {
for(val i <- res) {
for(val f <- i.fields) {
print("\t"+f.content.nativeValue)
}
println()
}
}

This code , f.content.nativeValue display value. i wnat how to extract id and name value.
send reply mail moc.liamg|5002ilarusnam#moc.liamg|5002ilarusnam

last edited on 1255253822|%e %b %Y, %H:%M %Z|agohover by mansur + show more
unfold How to Extract table values by mansurmansur, 1255253761|%e %b %Y, %H:%M %Z|agohover
Add a new comment
Page tags: dbc2 scala
page_revision: 6, last_edited: 1249620844|%e %b %Y, %H:%M %Z (%O ago)