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 {
}