Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class JDBC
- def teste()
- # This function takes a hashmap of vegetables and attempts to
- # find them from our grocery database. For each item found, we
- # call our 'makevegetablesoup' function.
- # Load all required gems
- require "rubygems"
- require "jdbc/mysql"
- require "java"
- begin
- # Prep the connection
- Java::com.mysql.jdbc.Driver
- userurl = "jdbc:mysql://localhost/vamos_testar"
- connSelect = java.sql.DriverManager.get_connection(userurl, "root", "")
- stmtSelect = connSelect.create_statement
- # Define the query
- selectquery = "SELECT * FROM transportes;"
- # Execute the query
- rsS = stmtSelect.execute_query(selectquery)
- # For each row returned do some stuff
- while (rsS.next) do
- veg = Hash.new
- veg["nome"] = rsS.getObject("ndt")
- puts veg["nome"]
- end
- end
- # Close off the connection
- stmtSelect.close
- connSelect.close
- return truth
- end
- end
- c = JDBC.new.teste
Add Comment
Please, Sign In to add comment