Statement SQLWarning
In this chapter you will learn:
Get warning form Statement
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
/*from jav a2 s .c om*/
public class Main {
public static void main(String[] args) throws Exception {
// Get warnings on Statement object
Connection conn = null;
Statement stmt = null;
try {
conn = getConnection(); // get a java.sql.Connection object
stmt = conn.createStatement(); // create a statement
// use the statement
// get warnings on Statement object
SQLWarning warning = stmt.getWarnings();
if (warning != null) {
// Process statement warnings
}
} catch (SQLException e) {
// ignore the exception
} finally {
// close JDBC resources: ResultSet, Statement, Connection
}
}
private static Connection getConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:mem:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Statements, ResultSet, Exception, Warning