Advertisement
Guest User

Scala connection test

a guest
May 1st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import java.sql.DriverManager
  2. import java.sql.Connection
  3.  
  4. object main {
  5. def main(args: Array[String]) {
  6. // connect to the database named "mysql" on the localhost
  7. val driver = "com.mysql.cj.jdbc.Driver"
  8. val url = "jdbc:mysql://localhost/Prueba?autoReconnect=true&useSSL=false"
  9. val username = "prueba"
  10. val password = "12345678"
  11.  
  12. // there's probably a better way to do this
  13. var connection:Connection = null
  14.  
  15. System.out.println("Connecting database...");
  16.  
  17. try {
  18. // make the connection
  19. Class.forName(driver)
  20. connection = DriverManager.getConnection(url, username, password)
  21.  
  22. // create the statement, and run the select query
  23. val statement = connection.createStatement()
  24. val resultSet = statement.executeQuery("SELECT Id, Nombre FROM Prueba")
  25. println("Connected")
  26. } catch {
  27. case e : Throwable => e.printStackTrace
  28. }
  29. connection.close()
  30.  
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement