IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2012, 12:18:37 PM (14 years ago)
Author:
rhenders
Message:

improvements to exception handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/mysql.py

    r33780 r33787  
    3434        self.dbPass = config.getDbPassword(dbType)
    3535
     36        # a user friendly connection sring
     37        connectionStr = self.dbName + "@" + self.dbHost
     38
    3639        # set up JDBC connection
    3740        self.url = "jdbc:mysql://"+self.dbHost+"/"+self.dbName+"?autoReconnect=true&user="+self.dbUser+"&password="+self.dbPass
     
    3942            self.con = DriverManager.getConnection(self.url)
    4043            self.connectionID = self.getLastConnectionID()
    41             self.logger.debug("MySQL connection to %s with ID %d" % (dbType, self.connectionID))
     44            self.logger.infoPair("Connected to MySQL Db", connectionStr)
    4245        except:
    43             self.logger.error("Unable to connect to " + self.url)
    44             self.everythingOK = False # TODO need this?
     46            self.logger.errorPair("Unable to connect to", connectionStr)
    4547            self.connected = False
    46             return
    47 
    48         self.everythingOK = True
     48            raise
     49
    4950        self.connected = True
    5051
     
    251252        except: pass
    252253            #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'")
     254
     255    '''
     256    Checks that we have a connection
     257    '''
     258    def isConnected(self):
     259
     260        try:
     261            self.con
     262            self.connected = True
     263        except:
     264            self.logger.errorPair("Not connected to", self.url)
     265            self.connected = False
     266
     267        return self.connected
     268
    253269    '''
    254270    TODO
    255271    '''
    256272    def execute(self, sql):
     273
     274        if not self.isConnected(): raise
    257275
    258276        stmt = self.con.createStatement()
     
    265283    def executeQuery(self, sql):
    266284
     285        if not self.isConnected(): raise
     286 
    267287        stmt = self.con.createStatement()
    268288        rs = stmt.executeQuery(sql)
Note: See TracChangeset for help on using the changeset viewer.