daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from java.sql import DriverManager
  2. from net.grinder.script.Grinder import grinder
  3. from net.grinder.script import Test
  4. from com.mysql.jdbc import Driver
  5.  
  6. test1 = Test(1, "Database insert")
  7. test2 = Test(2, "Database query")
  8.  
  9. #Load the MySQL JDBC driver.
  10. DriverManager.registerDriver(Driver())
  11.  
  12. def getConnection():
  13.     return DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
  14. "root", "Sasken@123")
  15.  
  16. def ensureClosed(object):
  17.     try: object.close()
  18.     except: pass
  19.  
  20. class TestRunner:
  21.     def __call__(self):
  22.         connection = None
  23.         insertStatement = None
  24.         queryStatement = None
  25.         print "connection"
  26.         try:
  27.             connection = getConnection()
  28.             insertStatement = connection.createStatement()
  29.             print "try connection"
  30.             test1.record(insertStatement)
  31.             print "test1 record"
  32.             insertStatement.execute("insert into testing values(%d)"
  33. (100))
  34.             print "insert"
  35.             test2.record(queryStatement)
  36.             print "test2 record"
  37.             queryStatement.executeQuery("select * from testing")
  38.             print "select"
  39.         except SyntaxError:
  40.                          print "can't execute db"
  41.  
  42.         finally:
  43.             ensureClosed(insertStatement)
  44.             ensureClosed(queryStatement)
  45.             ensureClosed(connection)
  46.  
  47. Thanks Advance.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top