Skip to content

Instantly share code, notes, and snippets.

@rodrigoSaladoAnaya
Last active August 29, 2015 14:00
Show Gist options
  • Save rodrigoSaladoAnaya/11063062 to your computer and use it in GitHub Desktop.
Save rodrigoSaladoAnaya/11063062 to your computer and use it in GitHub Desktop.
import org.vertx.groovy.core.http.RouteMatcher
import groovy.sql.Sql
// Use this driver and put the jar in the classpath:
// http://mvnrepository.com/artifact/postgresql/postgresql/8.4-702.jdbc4
def server = vertx.createHttpServer()
def routeMatcher = new RouteMatcher()
routeMatcher.getWithRegEx(".*") {req ->
def db = [
url:'jdbc:postgresql://localhost/databasname',
user:'bdusr',
password:'bdpwd',
driver:'org.postgresql.Driver'
]
Sql sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
def result = sql.rows("select * from portal_usuario")
sql.close()
req.response.end result.toString()
}
server.requestHandler(
routeMatcher.asClosure()
).listen(
8080,
'localhost'
)
//Show classpath elements
System.getProperty('java.class.path').split(':').each {
println "> ${it}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment