Guest User

Untitled

a guest
Apr 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. class JDBC
  2.  
  3. def teste()
  4. # This function takes a hashmap of vegetables and attempts to
  5. # find them from our grocery database. For each item found, we
  6. # call our 'makevegetablesoup' function.
  7.  
  8. # Load all required gems
  9. require "rubygems"
  10. require "jdbc/mysql"
  11. require "java"
  12.  
  13. begin
  14. # Prep the connection
  15. Java::com.mysql.jdbc.Driver
  16. userurl = "jdbc:mysql://localhost/vamos_testar"
  17. connSelect = java.sql.DriverManager.get_connection(userurl, "root", "")
  18. stmtSelect = connSelect.create_statement
  19.  
  20. # Define the query
  21. selectquery = "SELECT * FROM transportes;"
  22.  
  23. # Execute the query
  24. rsS = stmtSelect.execute_query(selectquery)
  25.  
  26. # For each row returned do some stuff
  27. while (rsS.next) do
  28. veg = Hash.new
  29. veg["nome"] = rsS.getObject("ndt")
  30. puts veg["nome"]
  31. end
  32. end
  33. # Close off the connection
  34. stmtSelect.close
  35. connSelect.close
  36. return truth
  37. end
  38. end
  39.  
  40. c = JDBC.new.teste
Add Comment
Please, Sign In to add comment