mysql数据库__Jdbc直接操作__PreparedStatement__新增数据表
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
mysql数据库__Jdbc直接操作__PreparedStatement__新增数据
表
⼀、代码如下
private void cTable() {
// TODO Auto-generated method stub
java.sql.PreparedStatement ps = null;
java.sql.Connection cn = null;
ResultSet rs = null;
try {
// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.mysql.jdbc.Driver").newInstance();
cn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/learn?user=root&password=&useUnicode=true&characterEncoding=UTF8");
ps = cn.prepareStatement("create table xxxx(aa int)");
int i= ps.executeUpdate();
System.out.println(i);
if(i>=1) {
System.out.println("数据表新增:成功");
}else {
System.out.println("数据表新增:失败");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
ps.close();
cn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}。