public static void main(String[] args) throws SQLException {
DataSource dataSource = new MysqlDataSource();
//String tabeleName = " test (id int ,name varchar(20))";
((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/java0531?characterEncoding=utf-8&useSSL=true");
((MysqlDataSource)dataSource).setUser("root");
((MysqlDataSource)dataSource).setPassword("*****");
Connection connection = dataSource.getConnection();
String sql = "create table test (id int ,name varchar(20))" ;
//删除
//String sql = "drop table test" ;
//String sql = "create table" + tabeleName;
PreparedStatement statement = connection.prepareStatement(sql);
int ret = statement.executeUpdate();
if(ret == 0) {
System.out.println("创建成功");
} else {
System.out.println("创建失败");
}
statement.close();
connection.close();
}
java JDBC编程 实现 mysql create table建表 操作
最新推荐文章于 2022-11-15 08:00:00 发布