Skip to content

Instantly share code, notes, and snippets.

@softwarerero
Last active December 19, 2015 05:49
Show Gist options
  • Save softwarerero/5906795 to your computer and use it in GitHub Desktop.
Save softwarerero/5906795 to your computer and use it in GitHub Desktop.
Trying to connect to MySQL from vert.x 2.0.0-CR2-SNAPSHOT.
...
dependencies {
compile "com.jetdrone:yoke:1.0.0-beta2"
compile "mysql:mysql-connector-java:5.1.25"
compile "com.bloidonia:mod-jdbc-persistor:2.0.0-CR1"
// If you're creating Groovy compiled verticles you may need the following dependencies
provided "org.codehaus.groovy:groovy-all:$groovyVersion"
provided "io.vertx:lang-groovy:$groovyLangModVersion@jar"
}
...
package de.suncom.cc.mdc
import groovy.sql.Sql
import org.vertx.groovy.platform.Verticle
class Server extends Verticle {
def config = [ address : 'test',
driver : 'com.mysql.jdbc.Driver',
url : 'jdbc:mysql://localhost:3306/mysql',
username : 'root',
password : '' ]
def start() {
def server = vertx.createHttpServer()
server.requestHandler{ request ->
// tryJdbcPersistor()
tryJdbc()
request.response.putHeader("Content-Type", "text/plain")
request.response.end("Hola")
}
server.listen(3000, "localhost")
}
def tryJdbcPersistor = {
container.deployModule( "com.bloidonia~mod-jdbc-persistor~2.0.0-CR1", config, 1 ) { asyncResult ->
if( asyncResult.succeeded() ) {
println "yes"
selectCajas()
} else {
println "Failed to deploy ${asyncResult.cause()}"
}
}
}
def selectCajas = {
vertx.eventBus.send(config.address, [action: 'select', stmt : 'SELECT Db from db'']) { reply ->
println reply.body().result
}
}
def tryJdbc = {
Class.forName(config.driver).newInstance()
def sql = Sql.newInstance( config.url, config.username, config.password)
sql.eachRow( 'select * from cajas' ) { println "$it" }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment