本文整理汇总了Python中java.lang.Class.forName方法的典型用法代码示例。如果您正苦于以下问题:Python Class.forName方法的具体用法?Python Class.forName怎么用?Python Class.forName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.Class
的用法示例。
在下文中一共展示了Class.forName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def __init__(self, connectURI, username, password, pool_name):
self.connectionPool = GenericObjectPool(None)
self._pool_name = pool_name
source = BasicDataSource()
source.setUrl(connectURI)
source.setUsername(username)
source.setPassword(password)
source.setInitialSize(1) # Number of connections to start with
source.setMinIdle(5) # Allow a bottom of 5 idle connections
source.setMaxActive(10) # Max of 10 database connection
source.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED)
source.setMinEvictableIdleTimeMillis(500)
self.connectionFactory = DataSourceConnectionFactory(source)
# Now we'll create the PoolableConnectionFactory, which wraps
# the "real" Connections created by the ConnectionFactory with
# the classes that implement the pooling functionality.
self.poolableConnectionFactory = PoolableConnectionFactory(self.connectionFactory,
self.connectionPool,
None,
None,
False,
True)
# Finally, we create the PoolingDriver itself...
Class.forName("org.apache.commons.dbcp.PoolingDriver")
driver = DriverManager.getDriver("jdbc:apache:commons:dbcp:")
# ...and register our pool with it.
driver.registerPool(self._pool_name, self.connectionPool)
示例2: connect_db
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def connect_db(jdbc_url, driverName):
try:
Class.forName(driverName).newInstance()
dbConn = DriverManager.getConnection(jdbc_url)
except Exception, msg:
print msg
sys.exit(1)
示例3: get_profiles
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def get_profiles(self):
head, tail = os.path.split(os.path.abspath(__file__))
settings_db = os.path.join(head, "GUI_Settings.db3")
try:
Class.forName("org.sqlite.JDBC").newInstance()
dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db)
self.Error_Message.setText("Database opened")
except SQLException as e:
self.Error_Message.setText("Error Opening Settings DB!")
try:
stmt = dbConn.createStatement()
SQL_Statement = "select profile_name from profiles where volatility_version = '" + self.Version_CB.getSelectedItem() + "';"
resultSet = stmt.executeQuery(SQL_Statement)
profile_list = []
while resultSet.next():
profile_list.append(resultSet.getString("profile_name"))
stmt.close()
dbConn.close()
return profile_list
except SQLException as e:
self.Error_Message.setText("Error Reading plugins")
stmt.close()
dbConn.close()
return "Error"
示例4: getConnection
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def getConnection(jdbc_url, driverName):
print "Using database at", jdbc_url, "driver", driverName
try:
Class.forName(driverName).newInstance()
except Exception, msg:
print msg
sys.exit(-1)
示例5: _jdbc_connect_jython
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def _jdbc_connect_jython(jclassname, jars, libs, *args):
if _converters is None:
from java.sql import Types
types = Types
types_map = {}
const_re = re.compile('[A-Z][A-Z_]*$')
for i in dir(types):
if const_re.match(i):
types_map[i] = getattr(types, i)
_init_converters(types_map)
global _java_array_byte
if _java_array_byte is None:
import jarray
def _java_array_byte(data):
return jarray.array(data, 'b')
# register driver for DriverManager
jpackage = jclassname[:jclassname.rfind('.')]
dclassname = jclassname[jclassname.rfind('.') + 1:]
# print jpackage
# print dclassname
# print jpackage
from java.lang import Class
from java.lang import ClassNotFoundException
try:
Class.forName(jclassname).newInstance()
except ClassNotFoundException:
if not jars:
raise
_jython_set_classpath(jars)
Class.forName(jclassname).newInstance()
from java.sql import DriverManager
return DriverManager.getConnection(*args)
示例6: check_Database_entries
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def check_Database_entries(self):
head, tail = os.path.split(os.path.abspath(__file__))
settings_db = os.path.join(head, "GUI_Settings.db3")
try:
Class.forName("org.sqlite.JDBC").newInstance()
dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db)
except SQLException as e:
self.Error_Message.setText("Error Opening Settings DB!")
try:
stmt = dbConn.createStatement()
SQL_Statement = 'Select Setting_Name, Setting_Value from settings;'
resultSet = stmt.executeQuery(SQL_Statement)
while resultSet.next():
if resultSet.getString("Setting_Name") == "Program_Exec_Name":
self.Program_Executable_TF.setText(resultSet.getString("Setting_Value"))
self.local_settings.setSetting('ExecFile', resultSet.getString("Setting_Value"))
self.local_settings.setSetting('Exec_Prog_Flag', 'true')
self.Exec_Program_CB.setSelected(True)
self.Program_Executable_TF.setEnabled(True)
self.Find_Program_Exec_BTN.setEnabled(True)
self.Error_Message.setText("Settings Read successfully!")
except SQLException as e:
self.Error_Message.setText("Error Reading Settings Database")
stmt.close()
dbConn.close()
示例7: __findGeoLocationsInDB
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def __findGeoLocationsInDB(self, databasePath, abstractFile):
if not databasePath:
return
try:
Class.forName("org.sqlite.JDBC") #load JDBC driver
connection = DriverManager.getConnection("jdbc:sqlite:" + databasePath)
statement = connection.createStatement()
except (ClassNotFoundException) as ex:
self._logger.log(Level.SEVERE, "Error loading JDBC driver", ex)
self._logger.log(Level.SEVERE, traceback.format_exc())
return
except (SQLException) as ex:
# Error connecting to SQL databse.
return
resultSet = None
try:
resultSet = statement.executeQuery("SELECT timestamp, latitude, longitude, accuracy FROM CachedPosition;")
while resultSet.next():
timestamp = Long.valueOf(resultSet.getString("timestamp")) / 1000
latitude = Double.valueOf(resultSet.getString("latitude"))
longitude = Double.valueOf(resultSet.getString("longitude"))
attributes = ArrayList()
artifact = abstractFile.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)
attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE, general.MODULE_NAME, latitude))
attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE, general.MODULE_NAME, longitude))
attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, general.MODULE_NAME, timestamp))
attributes.add(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, general.MODULE_NAME, "Browser Location History"))
# artifact.addAttribute(BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE.getTypeID(),moduleName, accuracy))
# NOTE: originally commented out
artifact.addAttributes(attributes);
try:
# index the artifact for keyword search
blackboard = Case.getCurrentCase().getServices().getBlackboard()
blackboard.indexArtifact(artifact)
except Blackboard.BlackboardException as ex:
self._logger.log(Level.SEVERE, "Unable to index blackboard artifact " + str(artifact.getArtifactTypeName()), ex)
self._logger.log(Level.SEVERE, traceback.format_exc())
MessageNotifyUtil.Notify.error("Failed to index GPS trackpoint artifact for keyword search.", artifact.getDisplayName())
except SQLException as ex:
# Unable to execute browser location SQL query against database.
pass
except Exception as ex:
self._logger.log(Level.SEVERE, "Error putting artifacts to blackboard", ex)
self._logger.log(Level.SEVERE, traceback.format_exc())
finally:
try:
if resultSet is not None:
resultSet.close()
statement.close()
connection.close()
except Exception as ex:
# Error closing database.
pass
示例8: connect
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def connect(dburl="jdbc:mysql://localhost:3306/mtgo", dbuser="root", dbpass=None):
try:
try:
Class.forName("com.mysql.jdbc.Driver").newInstance()
except NameError:
raise ErrorHandler("Internal MySQL error")
conn = DriverManager.getConnection(dburl, dbuser, dbpass)
except SQLException, error:
raise ErrorHandler("MySQL error: %s" % str(error))
示例9: __init__
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def __init__(self, *args, **kwds):
unittest.TestCase.__init__(self, *args, **kwds)
self._primitive_types = {
Class.forName('java.lang.Boolean'): Boolean,
Class.forName('java.lang.Integer'): Integer,
Class.forName('java.lang.Long'): Long,
Class.forName('java.lang.Double'): Double,
Class.forName('java.lang.String'): String
}
示例10: dbOpen
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def dbOpen(self):
self.database = "exp.db"
driver = "org.sqlite.JDBC"
self.url = "jdbc:sqlite:" + self.database
Class.forName(driver)
try:
self.db = DriverManager.getConnection(self.url);
self.stat = self.db.createStatement()
self.stat.executeUpdate("CREATE TABLE IF NOT EXISTS " + self.TABLENAME + " (" + self.EMAIL + " TEXT, " + self.HOST + " TEXT, " + self.NICK + " TEXT, " + self.EXP + " INTEGER);");
except SQLException, e:
self.requestAdd("ERROR : OPEN")
示例11: dbOpen
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def dbOpen(self):
self.database = "MACard.db"
driver = "org.sqlite.JDBC"
self.url = "jdbc:sqlite:" + self.database
Class.forName(driver)
try:
self.db = DriverManager.getConnection(self.url);
self.stat = self.db.createStatement()
self.stat.executeUpdate("CREATE TABLE IF NOT EXISTS " + self.TABLENAME + " ("+ self.CARDID + " INTEGER, " + self.COUNTRY + " TEXT, "+ self.CARDURL + " TEXT, " + self.CARDNAME + " TEXT, "+ self.CARDALTERNATIVE + " TEXT);");
except SQLException, e:
self.requestAdd("DB OPEN ERROR")
示例12: getConnection
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def getConnection(jdbc_url, driverName):
"""
Given the name of a JDBC driver class and the url to be used
to connect to a database, attempt to obtain a connection to
the database.
"""
try:
Class.forName(driverName).newInstance()
except Exception, msg:
print msg
sys.exit(-1)
示例13: dbOpen
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def dbOpen(self):
self.database = "CustomMsg.db"
driver = "org.sqlite.JDBC"
self.url = "jdbc:sqlite:" + self.database
Class.forName(driver)
try:
self.db = DriverManager.getConnection(self.url);
self.stat = self.db.createStatement()
self.stat.executeUpdate("CREATE TABLE IF NOT EXISTS " + self.TABLENAME + " ("+ self.HOST + " TEXT PRIMARY KEY, "+ self.MSG + " TEXT);");
except SQLException, e:
self.requestAdd("ERROR")
示例14: __init__
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def __init__(self, release, db_url, username, password, jdbc_driver):
self.jdbc_driver = jdbc_driver
self.password = password
self.username = username
self.db_url = db_url
Class.forName(jdbc_driver)
self._conn = DriverManager.getConnection(db_url, username, password)
wrapped_release = self.wrap_dict_as_obj(release)
self.release = wrapped_release
self.release_id = self.convert_id(wrapped_release.id)
if "originTemplateId" in release and release['originTemplateId'] is not None:
self.template_id = self.convert_id(wrapped_release.originTemplateId)
else:
self.template_id = "No Template"
示例15: actionPerformed
# 需要导入模块: from java.lang import Class [as 别名]
# 或者: from java.lang.Class import forName [as 别名]
def actionPerformed(self, event):
browsers = ["google-chrome", "firefox", "opera", "epiphany", "konqueror", "conkeror", "midori", "kazehakase", "mozilla"]
osName = System.getProperty("os.name")
helpHTML = ClassLoader.getSystemResource("help.html").toString()
if osName.find("Mac OS") == 0:
Class.forName("com.apple.eio.FileManager").getDeclaredMethod( "openURL", [String().getClass()]).invoke(None, [helpHTML])
elif osName.find("Windows") == 0:
Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + helpHTML)
else:
browser = None
for b in browsers:
if browser == None and Runtime.getRuntime().exec(["which", b]).getInputStream().read() != -1:
browser = b
Runtime.getRuntime().exec([browser, helpHTML])