1 17 package org.apache.log.output.db; 18 19 import java.io.PrintWriter ; 20 import java.sql.Connection ; 21 import java.sql.DriverManager ; 22 import java.sql.SQLException ; 23 import javax.sql.DataSource ; 24 25 31 public class DefaultDataSource 32 implements DataSource 33 { 34 private final String m_username; 35 private final String m_password; 36 private final String m_url; 37 38 private PrintWriter m_logWriter; 39 private int m_loginTimeout; 40 41 public DefaultDataSource( final String url, 42 final String username, 43 final String password ) 44 { 45 m_url = url; 46 m_username = username; 47 m_password = password; 48 49 m_logWriter = new PrintWriter ( System.err, true ); 50 } 51 52 57 public Connection getConnection() 58 throws SQLException 59 { 60 return getConnection( m_username, m_password ); 61 } 62 63 68 public Connection getConnection( final String username, final String password ) 69 throws SQLException 70 { 71 return DriverManager.getConnection( m_url, username, password ); 72 } 73 74 80 public int getLoginTimeout() 81 throws SQLException 82 { 83 return m_loginTimeout; 84 } 85 86 91 public PrintWriter getLogWriter() 92 throws SQLException 93 { 94 return m_logWriter; 95 } 96 97 103 public void setLoginTimeout( final int loginTimeout ) 104 throws SQLException 105 { 106 m_loginTimeout = loginTimeout; 107 } 108 109 public void setLogWriter( final PrintWriter logWriter ) 110 throws SQLException 111 { 112 m_logWriter = logWriter; 113 } 114 } 115 | Popular Tags |