Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.DriverManager
- import java.sql.Connection
- object main {
- def main(args: Array[String]) {
- // connect to the database named "mysql" on the localhost
- val driver = "com.mysql.cj.jdbc.Driver"
- val url = "jdbc:mysql://localhost/Prueba?autoReconnect=true&useSSL=false"
- val username = "prueba"
- val password = "12345678"
- // there's probably a better way to do this
- var connection:Connection = null
- System.out.println("Connecting database...");
- try {
- // make the connection
- Class.forName(driver)
- connection = DriverManager.getConnection(url, username, password)
- // create the statement, and run the select query
- val statement = connection.createStatement()
- val resultSet = statement.executeQuery("SELECT Id, Nombre FROM Prueba")
- println("Connected")
- } catch {
- case e : Throwable => e.printStackTrace
- }
- connection.close()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement