testquerytimeout.java

来自「Java Classic Examples是我买的两本书:《JAVA经典实例》和」· Java 代码 · 共 62 行

JAVA
62
字号
import java.sql.*;

public class TestQueryTimeOut
{
  public static void main(String[] args)
  {
    Statement statement = null;
    try
    {
      String url = "jdbc:odbc:technical_library";
      String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
      String username = "guest";
      String password = "guest";

      Class.forName(driver);
      Connection connection = 
              DriverManager.getConnection(url, username, password);
      statement = connection.createStatement();
      System.out.println("Driver          :  " + driver);
    }
    catch (ClassNotFoundException cnfe)
    {
      System.out.println(cnfe);
    }
    catch (SQLException sqle)
    {
      System.out.println(sqle);
    }
    // Put each method call in a separate try block to execute them all
    try
    {
      System.out.print("\nMaximum rows    :");
      int maxRows = statement.getMaxRows();
      System.out.print(maxRows == 0 ? " No limit" : " " + maxRows);
    }
    catch (SQLException sqle)
    {
      System.err.print(sqle);
    }
    try
    {
      System.out.print("\nMax field size  :");
      int maxFieldSize = statement.getMaxFieldSize();
      System.out.print(maxFieldSize == 0 ? " No limit" : " " + maxFieldSize);
    }
    catch (SQLException sqle)
    {
      System.err.print(sqle);
    }
    try
    {
      System.out.print("\nTimeout          :" );
      int queryTimeout = statement.getQueryTimeout();
      System.out.print(queryTimeout == 0 ? " No limit" : " " + queryTimeout);
    }
    catch (SQLException sqle)
    {
      System.err.print(sqle);
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?