package com.lin.jdbc_02;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/*
* 使用Statement执行对象执行DDL语句
* */
public class JdbcDemo_01 {
// 声明
private static String url=null;
private static String user=null;
private static String password=null;
private static Connection conn=null;
public static void main(String[] args) throws ClassNotFoundException, Exception {
url="jdbc:mysql://localhost:3306/mydb_01";
user="root";
password="123456";
// 1)注册驱动
Class.forName("com.mysql.jdbc.Driver");
//2)获取数据库的链接对象
Connection conn= DriverManager.getConnection(url, user, password);
//3)准备sql语句
String sql="create table stu("+
"id int primary key auto_increment,"+
"name varchar(10),"+
"age int,"+
"gender varchar(10)"+
");";
//4)创建Statement
Statement stmt=conn.createStatement();
//5)执行DDL语句
int count=stmt.executeUpdate(sql);
System.out.println(count);
System.out.println("创建成功");
if(stmt!=null) {
stmt.close();
}
if(conn!=null) {
conn.close();
}
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交