package Demo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Demo1 {
public static void main(String[] args) throws Exception {
Connection connection = null;
Statement statement = null;
try {
String url = "jdbc:mysql://localhost:3306/day16";
String user = "root";
String password = "root";
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url, user, password);
statement = connection.createStatement();
//执行的sql语句
String sql = "CREATE TABLE student(id INT PRIMARY KEY AUTO_INCREMENT,NAME VARCHAR(20),sex VARCHAR(2));";
//返回输出的结果(影响了几行)
int count = statement.executeUpdate(sql);
System.out.println("影响了" + count + "行");
} catch (Exception e) {
throw new RuntimeException();
}finally {
if(statement!=null){
statement.close();
}
if(connection!=null){
connection.close();
}
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Demo1 {
public static void main(String[] args) throws Exception {
Connection connection = null;
Statement statement = null;
try {
String url = "jdbc:mysql://localhost:3306/day16";
String user = "root";
String password = "root";
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url, user, password);
statement = connection.createStatement();
//执行的sql语句
String sql = "CREATE TABLE student(id INT PRIMARY KEY AUTO_INCREMENT,NAME VARCHAR(20),sex VARCHAR(2));";
//返回输出的结果(影响了几行)
int count = statement.executeUpdate(sql);
System.out.println("影响了" + count + "行");
} catch (Exception e) {
throw new RuntimeException();
}finally {
if(statement!=null){
statement.close();
}
if(connection!=null){
connection.close();
}
}
}
}