/*
* 按天建表 appVisit20130313 添加应用的访问详细情况 appVisitDate 当前时间 appVisit
* AppVisitBean实体
*/
public void addAppVisit(String appVisitDate) {
Connection conn = null;
String tableName = "appVisit" + appVisitDate;
try {
conn = getHibernateTemplate().getSessionFactory()
.getCurrentSession().connection();
DatabaseMetaData metaDate = conn.getMetaData();
ResultSet rs = metaDate.getTables(null, null, tableName,
new String[] { "TABLE" });
if (rs.next()) {
System.out.println(tableName + ": 表存在! ");
} else {
// System.out.println(tableName + ": 表 不 存在! ");
String sql ="CREATE TABLE `"+ tableName +"` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `appId` BIGINT(20) DEFAULT NULL, `userAttr` VARCHAR(255) DEFAULT NULL, `userCA` VARCHAR(255) DEFAULT NULL, `userIP` VARCHAR(255) DEFAULT NULL, `userMAC` VARCHAR(255) DEFAULT NULL, `visitDate` VARCHAR(255) DEFAULT NULL, `visitSource` VARCHAR(255) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=INNODB DEFAULT CHARSET=utf8;";
conn.prepareStatement(sql).execute();
//this.getHibernateTemplate().bulkUpdate(sql);
}
} catch (Exception e) {
e.printStackTrace();
}
}
使用Hibernate 操作原生sql语句建表
最新推荐文章于 2022-04-28 17:49:45 发布