Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. package test
  2. import java.sql.DriverManager
  3. //Connects to mysql DB using java.sql.DriverManager class
  4.  
  5. object test1 {
  6.  
  7. def main(args: Array[String]): Unit = {
  8. //Class.forName("com.mysql.jdbc.Driver")
  9.  
  10. val connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/retail_db","root","xxxx")
  11. val statement = connection.createStatement()
  12. val resultSet = statement.executeQuery("select * from customers limit 5")
  13. while (resultSet.next()) {
  14. println(resultSet.getInt(1) + " " + resultSet.getString(2))
  15. }
  16.  
  17. val meta = connection.getMetaData().getColumns(null, null, "customers", null)
  18. //println(connection.getNetworkTimeout)
  19. //println(DriverManager.getLoginTimeout)
  20. //println(resultSet.getMetaData().getColumnName(1) + " " + resultSet.getMetaData().getColumnName(2))
  21.  
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement