mysql数据库字段生成
Posted lljliulljn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql数据库字段生成相关的知识,希望对你有一定的参考价值。
import
static
java.lang.Character.toUpperCase;
import
java.sql.*;
import
java.util.*;
/**
*
* @author zhangjx
*/
public
class
ClassCreator
public
static
void
main(String[] args)
throws
Exception
create(
"org.om.model"
,
"users"
);
private
static
void
create(String pkg, String tablename)
throws
Exception
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource source =
new
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource();
source.setUrl(
"jdbc:mysql://localhost:3306/om?autoReconnect=true&characterEncoding=utf8"
); //数据库url
source.setUser(
"root"
);
//数据库账号
source.setPassword(
"admin"
);
//数据库密码
Connection conn = source.getConnection();
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getColumns(
null
,
"%"
, tablename,
null
);
// ResultSetMetaData rsd = rs.getMetaData();
// for(int i =1 ; i<=rsd.getColumnCount();i++)
// System.out.println(rsd.getColumnName(i));
//
StringBuilder sb =
new
StringBuilder();
sb.append(
"package "
+ pkg +
";"
+
"\\r\\n\\r\\n"
);
sb.append(
"import org.redkale.util.*;\\r\\n"
);
sb.append(
"import javax.persistence.*;\\r\\n"
);
sb.append(
"import org.redkale.convert.*;\\r\\n"
);
sb.append(
"import "
+ pkg.substring(
0
, pkg.lastIndexOf(
'.'
MySQL插入数据自动生成时间