📄 createmysqlemployeetable.java
字号:
package create;
import java.sql.*;
public class CreateMySQLEmployeeTable {
public CreateMySQLEmployeeTable(){
//定义数据库连接的驱动程序
String driver = "org.gjt.mm.mysql.Driver";
//定义MySQL数据库的连接地址
String url = "jdbc:mysql://localhost:3306/EmployeeEBKC10";
//声明连接类
Connection conn = null;
//创建employee数据表的SQL语句
String sql = "create table employeeTable(" +
" employeeId varchar(20) not null primary key," +
" departmentId varchar(20) not null," +
" employeeName varchar(50) not null," +
" phone varchar(50) not null," +
" address varchar(100) not null," +
" joinDate datetime not null," +
" resignDate datetime not null," +
" employeeStatus int default 0)";
try {
//使用JDBC技术创建数据库连接
Class.forName(driver);
//使用DriverManager类的getConnection()方法建立连接
conn = DriverManager.getConnection(url, "root", "test");
//通过Statement创建数据表
Statement stmt = conn.createStatement();
stmt.execute(sql);
System.out.println("数据表employeeTable创建成功");
}catch(Exception e){
System.out.println("数据表employeeTable创建失败");
e.printStackTrace();
}
}
public static void main(String[] args) {
new CreateMySQLEmployeeTable();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -