Connection: getWarnings() : Connection « java.sql « Java by API






Connection: getWarnings()

  
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLWarning;

public class Main {

  public static void main(String[] args) throws Exception {
    String dbURL = "jdbc:odbc:Companies";
    try {
      // 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);
    }
  }
}

           
         
    
  








Related examples in the same category

1.Connection.TRANSACTION_NONE
2.Connection.TRANSACTION_READ_COMMITTED
3.Connection.TRANSACTION_READ_UNCOMMITTED
4.Connection.TRANSACTION_REPEATABLE_READ
5.Connection.TRANSACTION_SERIALIZABLE
6.Connection: close()
7.Connection: commit()
8.Connection: createStatement()
9.Connection: createStatement(int resultSetType, int resultSetConcurrency)
10.Connection: getAutoCommit()
11.Connection: getCatalog()
12.Connection: getMetaData()
13.Connection: getTransactionIsolation()
14.Connection: nativeSQL(String sql)
15.Connection: prepareCall(String sql)
16.Connection: prepareStatement(String sql)
17.Connection: rollback()
18.Connection: rollback(Savepoint savepoint)
19.Connection: setAutoCommit(boolean autoCommit)
20.Connection: setSavepoint(String name)
21.Connection: setTransactionIsolation(int level)