JDK1.4 Logging Database Handler Implementation Source

zhaozj2021-02-16  66

Package com.benqguru.palau.log.jdk14log;

Import java.util.logging. *; import java.sql. *;

Class JDBCHANDAL EXTENDS HANDLER {

Public void flush () {}

Public void Publish (Logrecord Record) {Connection Conn = NULL;

PreparedStatement PSTMT = NULL;

Try {Driver D = (DRIVER) ("org.gjt.mm.mysql.driver"). NewInstance ()); DriverManager.RegisterDriver (D); conn = drivermanager.getConnection ("JDBC: mysql: / / localHost: 3306 / logtest "," root "," "); if (conn! = null) {Object [] content = record.getParameters (); string sql =" INSERT INTO MYLOG (Logtime, EventType) VALUES (? ,?) "; PSTMT = conn.preparestatement (SQL); PSTMT.SETLONG (1, Record.getMillis ()); PSTMT.SetString (2, (string) Content [0]); // Save LogInfo in Database PSTMT. EXECUTE ();}} catch (exception e) {E.PrintStackTrace ();} finally {if (conn! = null) {TRY {Conn.close ();} catch (exception ex) {ex.printstacktrace (); }}} F (pstmt! = Null) {Try {pstmt.close ();} catch (exception ex) {ex.printstacktrace ();} }}}

Public void close () throws java.lang.securityException {

}

转载请注明原文地址:https://www.9cbs.com/read-15904.html

New Post(0)