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

📄 createtables.java

📁 网络书店的设计与实现 网络书店的设计与实现
💻 JAVA
字号:
//: c15:jdbc:CreateTables.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// Creates database tables for 
// community interests database
import java.sql.*;

public class CreateTables {
  public static void main(String[] args) {
    DBStuff db = new DBStuff();
    try {
      // Load the driver (registers itself)
      Class.forName(db.getDriver());
    } catch(java.lang.ClassNotFoundException e) {
      System.err.print("ClassNotFoundException: ");
      e.printStackTrace();
    }
    try {
      Connection c = DriverManager.getConnection(
        db.getDbURL(),
        db.getUser(),
        db.getPassword());
      Statement s = c.createStatement();
      // SQL code:
      // Create the MEMBERS table
      try {
        s.executeUpdate( db.dropMemTbl );
      } catch(SQLException sqlEx) {
        String msg;
        msg = "Table MEMBERS not present. " +
              "Drop failed.";
        System.out.println(msg);
      } 
      s.executeUpdate( db.createMemTbl );
      s.executeUpdate( db.createMemIdx );
      
      // Create the EVENTS table
      try {
        s.executeUpdate( db.dropEvtTbl );
      } catch(SQLException sqlEx) {
        String msg;
        msg = "Table EVENTS not present. " +
              "Drop failed.";
        System.out.println(msg);
      } 
      s.executeUpdate( db.createEvtTbl );
      s.executeUpdate( db.createEvtIdx );
      
      // Create the EVTMEMS table
      try {
        s.executeUpdate( db.dropEMTbl );
      } catch(SQLException sqlEx) {
        String msg;
        msg = "Table EVTMEMS not present. " +
              "Drop failed.";
        System.out.println(msg);
      } 
      s.executeUpdate( db.createEMTbl );
      
      // Create the LOCATIONS table
      try {
        s.executeUpdate( db.dropLocTbl );
      } catch(SQLException sqlEx) {
        String msg;
        msg = "Table LOCATIONS not present. " +
              "Drop failed.";
        System.out.println(msg);
      } 
      s.executeUpdate( db.createLocTbl );
      s.executeUpdate( db.createLocIdx );
      
      s.close();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
} ///:~

⌨️ 快捷键说明

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