jfinal 数据库表生成器 链接远程数据库报错

private static String url = "jdbc:mysql://xx.xxx.xx.xx:3306/aaa?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&useSSL=false";
private static String name = "root";
private static String pwd = "password";
private static boolean flag = true;

private void  generator(){
    DruidPlugin dp = new DruidPlugin(url, name, pwd);
    ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);

    dp.start();
    arp.start();
    arp.setShowSql(flag);
    // base entity 所使用的包名
    String baseModelPackageName = "java";
    // base entity 文件保存路径
    String baseModelOutputDir = "baseEntity";
    // entity 所使用的包名 (MappingKit 默认使用的包名)
    String modelPackageName = "java";
    // entity 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
    String modelOutputDir = "Entity";

    // 创建生成器
    Generator gernerator = new Generator(dp.getDataSource(), baseModelPackageName, baseModelOutputDir,
            modelPackageName, modelOutputDir);
    // 设置数据库方言
    // gernerator.setDialect(new MysqlDialect());
    // 添加不需要生成的表名
    // gernerator.addExcludedTable("role");

    //是否生成链式 set方法
    gernerator.setGenerateChainSetter(true);
    // 设置是否在 Model 中生成 dao 对象
    gernerator.setGenerateDaoInModel(true);
    // 设置是否生成字典文件
    gernerator.setGenerateDataDictionary(true);
    // 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为
    // "User"而非 OscUser
    gernerator.setRemovedTableNamePrefixes("dad_");
    // 生成
    gernerator.generate();

Exception in thread "main" com.jfinal.plugin.activerecord.ActiveRecordException: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:55)

at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:226)

at com.backstage.neighbor.config.jfinal._JFinalGenerator.generator(_JFinalGenerator.java:20)

at com.backstage.neighbor.config.jfinal._JFinalGenerator.main(_JFinalGenerator.java:55)

Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1558)

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623)

at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:861)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1229)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1225)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:90)

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:43)

... 3 more

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)

at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)

at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)

at com.mysql.cj.NativeSession.connect(NativeSession.java:152)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)

... 13 more

Caused by: java.net.ConnectException: Connection timed out: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)

at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

at java.net.Socket.connect(Socket.java:589)

at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)

at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)

... 16 more


评论区

奔跑路上的小高

2019-08-13 15:54

URL连接上的xx是我后来改的

JFinal

2019-08-13 16:22

数据库没连上而已,改改配置,检查权限等方法弄好

此外, arp.setShowSql(...) 一定要放在 arp.start() 之后。也就是说配置工作完成以后,再 start()

奔跑路上的小高

2019-08-13 16:37

配置工作完成以后,再 start() 是不是arp.setShowSql(...)放在 arp.start()之前的意思?
还有现在我的数据库的配置都正确的 具体不知道是哪除了问题

奔跑路上的小高

2019-08-13 16:38

是不是这个生成 不能连接服务器上的数据库呢?

JFinal

2019-08-13 17:29

@奔跑路上的小高 纠正前面回复的一个笔误:
arp.setShowSql(...) 一定要放在 arp.start() 之前,而不是之后

热门反馈

扫码入社