// Format and print any warnings from the connection private static void checkForWarning(SQLWarning warn) throws SQLException { // If a SQLWarning object was given, display the // warning messages. Note that there could be // multiple warnings chained together if (warn != null) { System.out.println("*** Warning ***\n"); 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(); } } }
public void connect() { try { // Load the database driver Class.forName("net.sourceforge.jtds.jdbc.Driver"); // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); // Get a connection to the database String url = "jdbc:jtds:sqlserver://147.87.98.131:55783"; conn = DriverManager.getConnection(url, "se2012_red", "Thanuc57ch"); // Get a statement from the connection stmt = conn.createStatement(); // Print all warnings for (SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning()) { System.out.println("SQL Warning:"); System.out.println("State : " + warn.getSQLState()); System.out.println("Message: " + warn.getMessage()); System.out.println("Error : " + warn.getErrorCode()); } } catch (SQLException se) { System.out.println("SQL Exception:"); // Loop through the SQL Exceptions while (se != null) { System.out.println("State : " + se.getSQLState()); System.out.println("Message: " + se.getMessage()); System.out.println("Error : " + se.getErrorCode()); se = se.getNextException(); } } catch (Exception e) { System.out.println(e); } }