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

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


墨色风雨
浏览 1877回答 3
3回答

ibeautiful

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); //建立一个表}  

湖上湖

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();

蛊毒传说

use mysql;create table student(id number,name varchar(20),age number);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java