?? createtable.java
字號:
import java .sql.*;
public class CreateTable {
String username = "root";
String password = "right";
String jdbcDriver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/resturant";
public CreateTable(){
registerDriver(); //注冊驅動程序
}
public void registerDriver(){
try{
Class.forName(jdbcDriver);
}
catch(ClassNotFoundException e){
System.err.print(e.getMessage());
}
}
public void execute(){
Connection con = null;
Statement stmt = null;
String SQLCreate1="CREATE TABLE `resturant`.`tableinfo` (`oid` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,`number` VARCHAR(45) NOT NULL,`place` VARCHAR(45) NOT NULL,PRIMARY KEY (`oid`))ENGINE = InnoDB;";
String SQLCreate2="CREATE TABLE `resturant`.`customer` (`oid` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,`name` VARCHAR(45) NOT NULL,`phoneNumber` VARCHAR(45) NOT NULL,PRIMARY KEY (`oid`))ENGINE = InnoDB;";
String SQLCreate3="CREATE TABLE `resturant`.`walkin` (`oid` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,`covers` VARCHAR(45) NOT NULL,`date` VARCHAR(45) NOT NULL,`time` VARCHAR(45) NOT NULL,`table_id` VARCHAR(45) NOT NULL,PRIMARY KEY (`oid`))ENGINE = InnoDB;";
String SQLCreate4="CREATE TABLE `resturant`.`reservation` (`oid` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,`covers` VARCHAR(45) NOT NULL,`date` VARCHAR(45) NOT NULL,`time` VARCHAR(45) NOT NULL,`table_id` VARCHAR(45) NOT NULL,`custom_id` VARCHAR(45) NOT NULL,`arrivetime` VARCHAR(45),PRIMARY KEY (`oid`))ENGINE = InnoDB;";
try{
con=DriverManager.getConnection(url,username,password);
stmt=con.createStatement();
stmt.execute(SQLCreate1);
stmt.execute(SQLCreate2);
stmt.execute(SQLCreate3);
stmt.execute(SQLCreate4);
con.close();
}
catch(SQLException e){
System.err.println(e.getMessage());
}
finally{
try{
if(con!=null){
con.close();
}
if(stmt!=null){
stmt.close();
}
}catch(Exception ex){} //忽略
}
}
public static void main(String[] args){
CreateTable createTable=new CreateTable();
createTable.execute();
}
} //END OF CreateTable
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -