开发者社区> 问答> 正文

bae3.0 mysql 有时报错?报错

Jfinal 用的MySQL的数据源:MysqlDataSource ds = new MysqlDataSource();

Config:

MysqlDataSource ds = new MysqlDataSource();
ds.setUrl(getProperty("jdbcUrl"));
ds.setUser(getProperty("user"));
ds.setPassword(getProperty("password"));
		
// 配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin(ds);

mysql偶尔会报错,不是一直报错:

[Thread: qtp1450302257-3213]-[com.jfinal.core.ActionHandler.handle()]: /article/
com.jfinal.plugin.activerecord.ActiveRecordException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2 milliseconds ago.  The last packet sent successfully to the server was 2 milliseconds ago.
	at com.jfinal.plugin.activerecord.Db.update(Db.java:290)
	at com.newte88.controller.ArticleController.index(ArticleController.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:55)
	at com.newte88.interceptor.ResourceBundleInterceptor.intercept(ResourceBundleInterceptor.java:36)
	at com.jfinal.core.ActionInvocation.invoke(ActionInvocation.java:51)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:77)
	at com.newte88.handler.RewriteExtensionHandler.handle(RewriteExtensionHandler.java:60)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1491)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:518)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1097)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:447)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:200)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.Server.handle(Server.java:445)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:269)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
	at java.lang.Thread.run(Thread.java:724)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2 milliseconds ago.  The last packet sent successfully to the server was 2 milliseconds ago.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1129)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3720)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3609)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4160)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2768)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1651)
	at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:4198)
	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3592)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.GeneratedConstructorAccessor12.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
	at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:443)
	at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:141)
	at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:111)
	at com.jfinal.plugin.activerecord.DbKit.getConnection(DbKit.java:129)
	at com.jfinal.plugin.activerecord.Db.update(Db.java:287)
	... 31 more
Caused by: java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:189)
	at java.net.SocketInputStream.read(SocketInputStream.java:121)
	at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114)
	at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161)
	at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189)
	at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3163)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3620)
	... 55 more


展开
收起
爱吃鱼的程序员 2020-06-22 12:42:48 413 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    我把我原来的mopass版的直接迁徙过去了:

    里面用的  druid

    http://52jfinal.duapp.com/admin/druid/index.html

    我这2天监控下看有木有报错  MysqlDataSource是你楼主自己写的?目测试是数据库连接不稳定不是,MysqlDataSource是mysql驱动jar包里的。参考这个项目有关BAE的配置:  http://www.oschina.net/p/dreamlu 数据源配置和这个一样的。是不是和baemysql不支持长连接有关。用DriverManager,有没有好的改造方法。 请问MysqlDataSource是怎样连接bae的云数据库的,我用的是百度官方给的方法

    BAE3.0应该支持连接池的,你用druid试试!

    更多druid的配置:https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7%BD%AE%E5%B1%9E%E6%80%A7%E5%88%97%E8%A1%A8

    能用的话,麻烦也告知我下,我还没迁徙到3.0呢!刚申请到资源,看到

    0.4元/天就没啥动力了!

    用连接池暂时没有报错。
    2020-06-22 12:43:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像