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