我正在研究用于测试MySQL DB负载测试的Grinder框架。我能够连接MySQL数据库,但无法执行查询,我也没有收到任何错误消息。我的问题是如何在grinder框架中执行查询(Grinder将在Jython上运行)。
请找到下面的Jython脚本和程序正在执行“打印”test1记录“”步骤,之后它简单地跳过步骤,那个程序中的任何错误就像在查询中一样?
from java.sql import DriverManager
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from com.mysql.jdbc import Driver
test1 = Test(1, "Database insert")
test2 = Test(2, "Database query")
#Load the MySQL JDBC driver.
DriverManager.registerDriver(Driver())
def getConnection():
return DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "Sasken@123")
def ensureClosed(object):
try: object.close()
except: pass
class TestRunner:
def __call__(self):
connection = None
insertStatement = None
queryStatement = None
print "connection"
try:
connection = getConnection()
insertStatement = connection.createStatement()
print "try connection"
test1.record(insertStatement)
print "test1 record"
insertStatement.execute("insert into testing values(%d)"
(100))
print "insert"
test2.record(queryStatement)
print "test2 record"
queryStatement.executeQuery("select * from testing")
print "select"
except SyntaxError:
print "can\'t execute db"
finally:
ensureClosed(insertStatement)
ensureClosed(queryStatement)
ensureClosed(connection)
Thanks Advance.