Setting the Login Timeout : Driver « Database « Java Tutorial

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();

    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM survey");



  private static void outputResultSet(ResultSet rs) throws Exception {
    ResultSetMetaData rsMetaData = rs.getMetaData();
    int numberOfColumns = rsMetaData.getColumnCount();
    for (int i = 1; i < numberOfColumns + 1; i++) {
      String columnName = rsMetaData.getColumnName(i);
      System.out.print(columnName + "   ");


    while ( {
      for (int i = 1; i < numberOfColumns + 1; i++) {
        System.out.print(rs.getString(i) + "   ");


  private static Connection getHSQLConnection() throws Exception {
    String url = "jdbc:hsqldb:mem:data/tutorial";

    DriverManager.setLoginTimeout(60); // fail after 60 seconds

    return DriverManager.getConnection(url, "sa", "");

20.2.1.A List of JDBC Drivers: connection string, driver name
20.2.2.DriverManager.getDrivers(): enumerate all the loaded JDBC drivers:
20.2.3.Setting the Login Timeout
20.2.4.Get a List of all Available Parameters for Creating a JDBC Connection
20.2.5.String (Get name of property)
20.2.6.boolean java.sql.DriverPropertyInfo.required (Is property value required?)
20.2.7.String java.sql.DriverPropertyInfo.value (Get current value)
20.2.8.String java.sql.DriverPropertyInfo.description (Get description of property)
20.2.9.String[] java.sql.DriverPropertyInfo.choices (Get possible choices for property; if null, value can be any string)
20.2.10.DriverPropertyInfo[] java.sql.Driver.getPropertyInfo(String url, Properties info) java.sql.Driver.getMajorVersion() java.sql.Driver.getMinorVersion()
20.2.13.boolean java.sql.Driver.jdbcCompliant()
20.2.14.Getting Information about the Driver
20.2.15.Enable JDBC logging
20.2.16.Specify a CharSet when connecting to a DBMS
20.2.17.Listing All Available Parameters for Creating a JDBC Connection