⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbbean.java

📁 JAVA程序设计导论那本书上的一些源代码. 在学那本书的下来的
💻 JAVA
字号:
package chapter27;

import java.sql.*;

public class DBBean {
  private Connection connection = null;
  private String username;
  private String password;
  private String driver;
  private String url;

  /** Initialize database connection */
  public void initializeJdbc() {
    try {
      System.out.println("Driver is " + driver);
      Class.forName(driver);

      // Connect to the sample database
      connection = DriverManager.getConnection(url, username,
        password);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  /** Get tables in the database */
  public String[] getTables() {
    String[] tables = null;

    try {
      DatabaseMetaData dbMetaData = connection.getMetaData();
      ResultSet rsTables = dbMetaData.getTables(null, null, null,
        new String[] {"TABLE"});

      int size = 0;
      while (rsTables.next()) size++;

      rsTables = dbMetaData.getTables(null, null, null,
        new String[] {"TABLE"});

      tables = new String[size];
      int i = 0;
      while (rsTables.next())
        tables[i++] = rsTables.getString("TABLE_NAME");
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

    return tables;
  }

  /** Return connection property */
  public Connection getConnection() {
    return connection;
  }

  public void setUsername(String newUsername) {
    username = newUsername;
  }

  public String getUsername() {
    return username;
  }

  public void setPassword(String newPassword) {
    password = newPassword;
  }

  public String getPassword() {
    return password;
  }

  public void setDriver(String newDriver) {
    driver = newDriver;
  }

  public String getDriver() {
    return driver;
  }

  public void setUrl(String newUrl) {
    url = newUrl;
  }

  public String getUrl() {
    return url;
  }
}

⌨️ 快捷键说明

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