关于.jar的文件在cmd中无法连接数据库的问题

我使用一个.jar的文件,想在cmd中以“java -jar *.jar”的格式运行,方便system.println()一些信息,该jar包中包含数据库连接内容,在我关闭comodo防火墙和windows防火墙的情况下,该文件无法运行,在我开启comodo防火墙时,会提示是否连接internet(实际上是127.0.0.1的本地连接),点击同意可正常连接。坑爹的是,我只开启windows防火墙而不开启comodo,系统无任何提示,不能运行此程序,真心不知道是被哪个防火墙拦截的。

另外,如果点击同意之后,后续运行相同程序没有问题会可以继续运行,但是更新之后便必须开启comodo重新同意才可以在cmd中运行该jar包,因此调查一下不开启comodo而jar包被拦截到底是什么原因。

附录:等一段时间后,cmd弹出异常提示如下:

关于.jar的文件在cmd中无法连接数据库的问题
  1 Success loading Mysql Driver!
  2 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link f
  3 lure
  4 
  5 The last packet sent successfully to the server was 0 milliseconds ago. The dr
  6 er has not received any packets from the server.
  7         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Metho
  8 
  9         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstru
 10 orAccessorImpl.java:39)
 11         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Delegatin
 12 onstructorAccessorImpl.java:27)
 13         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 14         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
 15         at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java
 16 121)
 17         at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:357)
 18         at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2482)
 19         at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java
 20 519)
 21         at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2304)
 22         at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
 23         at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
 24         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Metho
 25 
 26         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstru
 27 orAccessorImpl.java:39)
 28         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Delegatin
 29 onstructorAccessorImpl.java:27)
 30         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 31         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
 32         at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
 33         at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.ja
 34 :346)
 35         at java.sql.DriverManager.getConnection(DriverManager.java:582)
 36         at java.sql.DriverManager.getConnection(DriverManager.java:185)
 37         at ReadAndWriteData_use.getConnection(ReadAndWriteData_use.java:71)
 38         at ReadAndWriteData_use.ConnectMysql(ReadAndWriteData_use.java:46)
 39         at ReadAndWriteData_use.main(ReadAndWriteData_use.java:212)
 40 Caused by: java.net.ConnectException: Connection refused: connect
 41         at java.net.PlainSocketImpl.socketConnect(Native Method)
 42         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
 43         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
 44         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
 45         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
 46         at java.net.Socket.connect(Socket.java:529)
 47         at java.net.Socket.connect(Socket.java:478)
 48         at java.net.Socket.<init>(Socket.java:375)
 49         at java.net.Socket.<init>(Socket.java:218)
 50         at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.
 51 va:259)
 52         at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:307)
 53         ... 17 more
 54 Success connect Mysql server!
 55 get data error!java.lang.NullPointerException
 56         at ReadAndWriteData_use.ConnectMysql(ReadAndWriteData_use.java:49)
 57         at ReadAndWriteData_use.main(ReadAndWriteData_use.java:212)
 58 开始........
 59 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link f
 60 lure
 61 
 62 The last packet sent successfully to the server was 0 milliseconds ago. The dr
 63 er has not received any packets from the server.
 64         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Metho
 65 
 66         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstru
 67 orAccessorImpl.java:39)
 68         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Delegatin
 69 onstructorAccessorImpl.java:27)
 70         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 71         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
 72         at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java
 73 121)
 74         at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:357)
 75         at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2482)
 76         at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java
 77 519)
 78         at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2304)
 79         at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
 80         at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
 81         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Metho
 82 
 83         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstru
 84 orAccessorImpl.java:39)
 85         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Delegatin
 86 onstructorAccessorImpl.java:27)
 87         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 88         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
 89         at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
 90         at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.ja
 91 :346)
 92         at java.sql.DriverManager.getConnection(DriverManager.java:582)
 93         at java.sql.DriverManager.getConnection(DriverManager.java:185)
 94         at ReadAndWriteData_use.getConnection(ReadAndWriteData_use.java:71)
 95         at ReadAndWriteData_use.readFile(ReadAndWriteData_use.java:105)
 96         at ReadAndWriteData_use.main(ReadAndWriteData_use.java:218)
 97 Caused by: java.net.ConnectException: Connection refused: connect
 98         at java.net.PlainSocketImpl.socketConnect(Native Method)
 99         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
100         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
101         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
102         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
103         at java.net.Socket.connect(Socket.java:529)
104         at java.net.Socket.connect(Socket.java:478)
105         at java.net.Socket.<init>(Socket.java:375)
106         at java.net.Socket.<init>(Socket.java:218)
107         at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.
108 va:259)
109         at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:307)
110         ... 17 more
111 step1:getConnection() -> success!
112 Exception in thread "main" java.lang.NullPointerException
113         at ReadAndWriteData_use.readFile(ReadAndWriteData_use.java:107)
114         at ReadAndWriteData_use.main(ReadAndWriteData_use.java:218)
115 Success loading Mysql Driver!
关于.jar的文件在cmd中无法连接数据库的问题

 

关于.jar的文件在cmd中无法连接数据库的问题,布布扣,bubuko.com

关于.jar的文件在cmd中无法连接数据库的问题

上一篇:java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和总结 转


下一篇:SQL Server已提交读快照隔离级别的设置