List of usage examples for java.sql DriverManager setLogWriter
public static void setLogWriter(java.io.PrintWriter out)
PrintWriter
object that is used by the DriverManager
and all drivers. From source file:Main.java
public static void main(String[] args) throws Exception { String dbURL = "jdbc:odbc:Companies"; try {/*from w w w .ja v a 2s . co m*/ // Load the jdbc-odbc bridge driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Enable logging DriverManager.setLogWriter(new PrintWriter((System.err))); System.out.println("Getting Connection"); Connection conn = DriverManager.getConnection(dbURL, "user", "password"); SQLWarning warn = conn.getWarnings(); while (warn != null) { System.out.println("SQLState: " + warn.getSQLState()); System.out.println("Message: " + warn.getMessage()); System.out.println("Vendor: " + warn.getErrorCode()); System.out.println(""); warn = warn.getNextWarning(); } conn.close(); } catch (ClassNotFoundException e) { System.out.println("Can't load driver " + e); } catch (SQLException e) { System.out.println("Database access failed " + e); } }
From source file:Main.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String URL = "jdbc:odbc:dbName"; Connection dbConn = DriverManager.getConnection(URL, "user", "pass"); PrintWriter w = new PrintWriter(new OutputStreamWriter(System.out)); DriverManager.setLogWriter(w); dbConn.close();/*from w w w . java2 s .c om*/ PreparedStatement prepstmt; prepstmt = dbConn.prepareStatement("SELECT id FROM employee"); prepstmt.execute(); prepstmt.close(); dbConn.close(); }
From source file:TestDebug_MySQL.java
public static void main(String[] args) { Connection conn = null;//from ww w . j a v a2 s .c om try { PrintWriter pw = new PrintWriter(new FileOutputStream("mysql_debug.txt")); DriverManager.setLogWriter(pw); conn = getConnection(); String tableName = "myTable"; System.out.println("tableName=" + tableName); System.out.println("conn=" + conn); System.out.println("rowCount=" + countRows(conn, tableName)); } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:Connect.java
public static void main(String[] av) { String dbURL = "jdbc:odbc:Companies"; try {/* w w w. j a v a 2 s . c om*/ // Load the jdbc-odbc bridge driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Enable logging DriverManager.setLogWriter(new PrintWriter((System.err))); System.out.println("Getting Connection"); Connection conn = DriverManager.getConnection(dbURL, "ian", ""); // user, // passwd // If a SQLWarning object is available, print its // warning(s). There may be multiple warnings chained. SQLWarning warn = conn.getWarnings(); while (warn != null) { System.out.println("SQLState: " + warn.getSQLState()); System.out.println("Message: " + warn.getMessage()); System.out.println("Vendor: " + warn.getErrorCode()); System.out.println(""); warn = warn.getNextWarning(); } // Do something with the connection here... conn.close(); // All done with that DB connection } catch (ClassNotFoundException e) { System.out.println("Can't load driver " + e); } catch (SQLException e) { System.out.println("Database access failed " + e); } }
From source file:Main.java
private static Connection getHSQLConnection() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); String url = "jdbc:hsqldb:mem:data/tutorial"; DriverManager.setLogWriter(new PrintWriter("yourFileName.log")); return DriverManager.getConnection(url, "sa", ""); }
From source file:OracleDataSource.java
public void setLogWriter(PrintWriter writer) throws SQLException { DriverManager.setLogWriter(writer); }
From source file:iudex.da.DataSourceFactory.java
public void setLogWriter() { LogWriter lw = new LogWriter("iudex.da.driver"); lw.setRemovePattern(LOG_REMOVE_PATTERN); DriverManager.setLogWriter(new PrintWriter(lw, true)); }
From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.VirtualSQLDataSource.java
public void setLogWriter(PrintWriter out) throws SQLException { DriverManager.setLogWriter(new PrintWriter(new LoggerOutputStream())); }
From source file:com.adaptris.jdbc.connection.FailoverDataSource.java
/** * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter) *//* w ww . j a v a 2 s .c om*/ @Override public void setLogWriter(PrintWriter logWriter) throws SQLException { DriverManager.setLogWriter(logWriter); }
From source file:net.sourceforge.squirrel_sql.client.Application.java
@SuppressWarnings("deprecation") private void setupJDBCLogging() { // If logging has changed. if (_jdbcDebugType != _prefs.getJdbcDebugType()) { final ApplicationFiles appFiles = new ApplicationFiles(); final File outFile = appFiles.getJDBCDebugLogFile(); // Close any previous logging. DriverManager.setLogStream(null); if (_jdbcDebugOutputStream != null) { _jdbcDebugOutputStream.close(); _jdbcDebugOutputStream = null; }// w w w . j a va 2s. c o m DriverManager.setLogWriter(null); if (_jdbcDebugOutputWriter != null) { _jdbcDebugOutputWriter.close(); _jdbcDebugOutputWriter = null; } if (_prefs.isJdbcDebugToStream()) { try { // i18n[Application.info.setjdbcdebuglog=Attempting to set JDBC debug log to output stream] s_log.debug(s_stringMgr.getString("Application.info.setjdbcdebuglog")); _jdbcDebugOutputStream = new PrintStream(new FileOutputStream(outFile)); DriverManager.setLogStream(_jdbcDebugOutputStream); // i18n[Application.info.setjdbcdebuglogsuccess=JDBC debug log set to output stream // successfully] s_log.debug(s_stringMgr.getString("Application.info.setjdbcdebuglogsuccess")); } catch (IOException ex) { final String msg = s_stringMgr.getString("Application.error.jdbcstream"); s_log.error(msg, ex); showErrorDialog(msg, ex); DriverManager.setLogStream(System.out); } } if (_prefs.isJdbcDebugToWriter()) { try { // i18n[Application.info.jdbcwriter=Attempting to set JDBC debug log to writer] s_log.debug(s_stringMgr.getString("Application.info.jdbcwriter")); _jdbcDebugOutputWriter = new PrintWriter(new FileWriter(outFile)); DriverManager.setLogWriter(_jdbcDebugOutputWriter); // i18n[Application.info.jdbcwritersuccess=JDBC debug log set to writer successfully] s_log.debug(s_stringMgr.getString("Application.info.jdbcwritersuccess")); } catch (IOException ex) { final String msg = s_stringMgr.getString("Application.error.jdbcwriter"); s_log.error(msg, ex); showErrorDialog(msg, ex); DriverManager.setLogWriter(new PrintWriter(System.out)); } } _jdbcDebugType = _prefs.getJdbcDebugType(); } }