如何用java创建MYSQL的数据表?

提供一下详细的代码!!!
2024-12-28 20:22:31
推荐回答(4个)
回答1:

class.forname("oracle.jdbc.driver.OracleDriver");//加载数据库驱动

String url="jdbc:oracle:thin:@localhost:1521:db_name";
String sql="CREATE TABLE table(filed1 varchar2(2),filed2 varchar2(2))";

Connection conn=DriverManager.getConnection(url,"scott","tiger");//建立数据库连接

if(!conn.isClose()){
Statement stmt = conn.createStatement();
stmt.executeUPDATE(sql); //建立一个表

}

回答2:

use mysql;

create table student(
id number,
name varchar(20),
age number
);

回答3:

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");

String sql = "CREATE TABLE tableName (id int not null, name varchar(20) not null, age int null, primary key (id));";

PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();

回答4:

百度一下,你就知道