本文整理汇总了Python中java.lang.Class类的典型用法代码示例。如果您正苦于以下问题:Python Class类的具体用法?Python Class怎么用?Python Class使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Class类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_Database_entries
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()
示例2: connect_db
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: __init__
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)
示例4: getConnection
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
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: get_profiles
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"
示例7: __findGeoLocationsInDB
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
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__
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: getConnection
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)
示例11: dbOpen
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")
示例12: dbOpen
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")
示例13: dbOpen
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: emit_java_expression
def emit_java_expression(klass, name):
try:
cog.out(CONVERSIONS[klass].to_java_format % name)
except KeyError:
if klass.isPrimitive():
raise Exception("You need a converter for %s" % klass.getName())
simpleName = Class.getName(klass)
if klass.isArray():
simpleName = Class.getSimpleName(klass)
if simpleName != 'java.lang.Object':
cog.out('(%s)' % simpleName)
cog.out('%s.__tojava__(%s.class)' % (name, simpleName))
示例15: __init__
def __init__(self, dbType):
log_file_name = "history_%s.log" % datetime.now().strftime("%Y%m%d")
self.logger = Logger.getLog(log_file_name)
self.conn = None
self.__stmt__ = None
self.__rs__ = None
config = dbType
if config:
try:
Class.forName(config["DRIVER"]).newInstance()
self.conn = DriverManager.getConnection(config["URL"], config["USER"], config["PASSWD"])
except SQLException, e:
self.logger.error("(db.py => __init__)Get %s connection error! \n %s" % (dbType, str(e)))
raise Exception