数据库配置文件:jdbcUrl=jdbc:sqlserver://192.168.0.30:1433;DatabaseName=Hynet
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
user=sa
password=qhhy*data
devMode=true
config文件:public static DataSource getDataSource() {
//加载配置文件
Prop p = PropKit.use("config.properties");
//创建c3p0连接
C3p0Plugin c3p0Plugin = new C3p0Plugin(p.get("jdbcUrl"), p.get("user"), p.get("password") ,p.get("driver"));
c3p0Plugin.start();
return c3p0Plugin.getDataSource();
}
public static void main(String[] args) {
// base model 所使用的包名
String baseModelPackageName = "com.demo.model.base";
// base model 文件保存路径
String baseModelOutputDir = PathKit.getWebRootPath() + "/../src/com/demo/common/model/base";
System.out.println("111111111111");
System.out.println(baseModelOutputDir);
// model 所使用的包名 (MappingKit 默认使用的包名)
String modelPackageName = "com.demo.common.model";
// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
String modelOutputDir = baseModelOutputDir + "/..";
// 创建生成器
Generator gernerator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
// 设置数据库方言
//gernerator.setDialect(new MysqlDialect());
// 添加不需要生成的表名
gernerator.addExcludedTable("_EC_DataPort","_EC_SalesOrder","_Ws_DataPort","_WS_Delivery","_WS_Log","_WS_PO_Delivery","_WS_SO_EC","_WS_Success_Log");
// 设置是否在 Model 中生成 dao 对象
gernerator.setGenerateDaoInModel(true);
// 设置是否生成字典文件
gernerator.setGenerateDataDictionary(false);
// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
//gernerator.setRemovedTableNamePrefixes("t_");
// 生成
gernerator.generate();
}
报错信息:Exception in thread "main" java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: '`' 附近有语法错误。
at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:102)
at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:262)
at com.demo.common.JfinalGenerator.main(JfinalGenerator.java:47)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: '`' 附近有语法错误。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:786)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:685)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:620)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:327)
at com.jfinal.plugin.activerecord.generator.MetaBuilder.buildColumnMetas(MetaBuilder.java:222)
at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:97)
... 2 more
activeRecordPlugin.setDialect(new SqlServerDialect());
如果是生成器,要配置:
generator.setDialect(new SqlServerDialect());