JDBC连接问题 到主机 的 TCP/IP 连接失败

myeclipse通过jar包连接sql server 2012总是失败。
我ping 127.0.0.1可以,telnet 127.0.0.1 1433就出错,但是telnet localhost 1433没问题。
数据库通过新建查询发现1433是开着的
2017-10-18 16:31:35.230 spid13s Server is listening on [ 'any' 1433].
2017-10-18 16:31:35.290 服务器 Server is listening on [ ::1 1434].

1个回答

是不是有代理或防火墙等

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
本机JDBC连接SQL Server报:通过端口1433连接到主机的TCP/IP失败,bad address: connect,

本机JDBC连接SQL Server报:通过端口1433连接到主机的TCP/IP失败,bad address: connect, 但是局域网内同事用我的代码连我的数据库都没问题,是不是我本机配置那边有问题?折腾好久都没搞定,说明:数据库和代码都是没问题的,各位大神求教~

通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败

![图片说明](https://img-ask.csdn.net/upload/201906/12/1560348780_18659.png)![图片说明](https://img-ask.csdn.net/upload/201906/12/1560348847_693090.png)![图片说明](https://img-ask.csdn.net/upload/201906/12/1560348854_866690.png) ## # 错误:通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。 做java实验时,要求链接数据库,已下载jdbc6.0版本,但是MSSQLSERVER服务启动不了,几经查找都不行,求助大佬们!上图

通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。

com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。

大神在哪? 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。

十月 10, 2015 12:14:16 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:14 Prelogin error: host localhost port 1433 Unexpected end of prelogin response after 0 bytes read 十月 10, 2015 12:14:16 下午 org.apache.catalina.core.StandardContext loadOnStartup 严重: Servlet threw load() exception com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“驱动程序收到意外的登录前响应。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接。该驱动程序只能与 SQL Server 2000 或更高版本一起使用。”。 at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1368) at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1355) at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:1151) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1054) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:187) at org.logicalcobwebs.proxool.DefaultConnectionBuilder.buildConnection(DefaultConnectionBuilder.java:39) at org.logicalcobwebs.proxool.Prototyper.buildConnection(Prototyper.java:159) at org.logicalcobwebs.proxool.ConnectionPool.getConnection(ConnectionPool.java:211) at org.logicalcobwebs.proxool.ProxoolDataSource.getConnection(ProxoolDataSource.java:97) at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353) at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:558) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:374) at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) at com.eweaver.base.security.service.logic.AcegiCacheManager$$EnhancerByCGLIB$$6373dcba.getAuthorityFromCache(<generated>) at com.eweaver.base.security.service.acegi.DBMethodDefinitionSource.lookupAttributes(DBMethodDefinitionSource.java:74) at org.acegisecurity.intercept.method.AbstractMethodDefinitionSource.getAttributes(AbstractMethodDefinitionSource.java:51) at org.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:229) at org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:63) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) at org.light.portal.core.service.spring.PortalServiceImpl$$EnhancerByCGLIB$$38b0f553.init(<generated>) at org.light.portlet.core.impl.PortletContainerImpl.init(PortletContainerImpl.java:99) at org.light.portal.Servlet.init(Servlet.java:77) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:785) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445) at org.apache.catalina.core.StandardService.start(StandardService.java:519) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:581) 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 org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

jdbc通过1433端口连接sqlserver数据库总是失败

最近在做一个小项目,在android的额产品里塞中直接用jdbc连接本地服务器的sqlserver数据库的时候出现这个错误:“请验证连接属性,并检查 SQL Server 的实例正在主机上运行, 且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接” 在网上查阅了很多资料,server的端口都是1433,IP2也启动了,sql实例也都启动了,server服务也重新启动了,防火墙也关闭了,但是就是一直连不上,大家有什么好的方法吗 这是简单的测试代码: package com.example.myfinallytest; import android.support.v7.app.ActionBarActivity; import android.widget.TextView; import android.os.Bundle; import android.os.StrictMode; import java.sql.*; public class MainActivity extends ActionBarActivity { private TextView Text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); Text = (TextView)findViewById(R.id.Test); System.out.println("1"); Connect(); System.out.println("2"); } public Connection Connect(){ String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载驱动 System.out.println("加载驱动"); String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=Test"; //连接数据库 System.out.println("加载URL"); String userName = "sa"; //服务器用户名 String userPassword = "12345"; //服务器密码 Connection Con = null; try{ System.out.println("进入try"); Class.forName(driverName).newInstance(); //加载驱动到java虚拟机 System.out.println("加载JAVA虚拟机"); Con = DriverManager.getConnection(dbURL,userName,userPassword); Text.setText("连接成功!"); System.out.println("连接成功!"); }catch(Exception e){ e.printStackTrace(); Text.setText("连接失败!"); System.out.println("连接失败!"); } return Con; } } ![![![![图片说明](https://img-ask.csdn.net/upload/201605/05/1462417358_289781.png)图片说明](https://img-ask.csdn.net/upload/201605/05/1462417352_919748.png)图片说明](https://img-ask.csdn.net/upload/201605/05/1462417346_945896.png)图片说明](https://img-ask.csdn.net/upload/201605/05/1462417340_452229.png)

端口连接主机连接不上

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 192.168.20.103 的 TCP/IP 连接失败。错误:“connect timed out。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。

mybatis如何通过jdbc连接sqlserver数据库

我用的NavicatServer软件 制作的数据库表,并且可以连接上 有ip地址 用户名和密码 在junit测试的时候 报错: **Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 127.0.0.1,1433 的 TCP/IP 连接失败。错误:“null。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。** 在网上找了很多办法没有解决。 1先是从官网下载了sqlserver的安装包 安装上了 2有下载了jdbc连接sqlserver的驱动包 这样反复几次还是这个报错信息 问题已经解决了:谢谢大家。 只需要更改url上的IP地址和端口号即可。无需在本地安装sqlserver数据库啦!

我用MyEclipse连接SQL Server出现如下错误,求教(代码是借用的,我主要想看看怎样连接数据库):

import java.sql.*; public class Test { public static void main(String[] srg) { String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // 加载JDBC驱动 String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=Student"; // 连接服务器和数据库 String userName = "sa"; // 默认用户名 String userPwd = "sa123"; // 密码 String sql="select * from student"; String s1=null; Connection dbConn = null; Statement st=null; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL,userName,userPwd); st = (Statement) dbConn.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = st.executeQuery(sql); while (rs.next()) { s1 = rs.getString(1).trim(); System.out.println(s1); } System.out.println("数据库连接成功!"); } catch (Exception e) { System.err.println("OpenConn:" + e.getMessage()); } } } 我安装了sqljdbc_1.1的驱动程序,过程也按照所提供的方法进行设置的(设置TCP/IP的端口是1433),却出现以下错误: OpenConn:到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect 望指教

sqlserver2012无法通过jdbc连接MyElicpse 求个大神

使用sqljdbc.jar连接jdbc时: 通过端口 1433 连接到主机 127.0.0.1 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。 代码如下: String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";//驱动器 String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=xxxx"; String user = "sa";//用户名 String password = "sa";//密码 try { Class.forName(driver); // 加载数据库驱动 // 构建连接 Connection conn = DriverManager.getConnection(url, user, password); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); 防火墙已经关闭 没有阻止接口 telnet localhost 1433是通的 但是127.0.0.1 1433就提示连接端口:1433 失败 ping 127.0.0.1是没问题的 C盘etc/hosts中的对应localhost与127.0.0.1的内容为: # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost Sqlserver配置器已经打开 IIPALL的固定端口是1433 一直保持侦听状态 只有一个实例MSSQLSERVER windows事件日志上的错误是:服务器无法在 'any' <ipv4> 1434 上侦听。错误: 0x277a。若要继续,请通知您的系统管理员。 查看sqlserver 2012日志错误如下: Server failed to listen on 'any' <ipv4> 1434. Error: 0x277a. To proceed, notify your system administrator 错误: 26024,严重性: 16,状态: 1。 电脑已经重装成win7了 还是这个问题 sql可以和visual studio 2012连接 但是无法和MyElicpse连接 在cmd中执行netstat -ano 只有TCP [::]:1433接口在监听 找不到0.0.0.0:1433和127.0.0.1:1433这两个接口 1434只有UDP [::]:1434和0.0.0.0:1434 执行tasklist|findstr 2448(1433端口PID) 显示进程为sqlservr.exe 1433没有被占用 使用的jar包是sqljdbc4.jar ![图片说明](https://img-ask.csdn.net/upload/201610/01/1475290507_428583.png) ![图片说明](https://img-ask.csdn.net/upload/201610/01/1475290521_744595.png) ![图片说明](https://img-ask.csdn.net/upload/201610/01/1475290568_511606.png) ![图片说明](https://img-ask.csdn.net/upload/201610/01/1475290580_258520.png) ![图片说明](https://img-ask.csdn.net/upload/201610/01/1475290588_54854.png) 在之前使用win8的时候 有段时间是可以连接的 当时没有加入tomcat 大约有2到3个月没有使用这个jdbc 再拿出来学习jsp的时候 就一直提示这个错误 因为我要使用tomcat做jsp 要连接jdbc 所以这个问题很急 求大神解决一下啊 重装了好几次系统了 要崩溃了

jdbc连接sql server2005出现问题

![![图片说明](https://img-ask.csdn.net/upload/201607/12/1468312796_214210.png)图片说明](https://img-ask.csdn.net/upload/201607/12/1468312786_598804.png)![图片说明](https://img-ask.csdn.net/upload/201607/12/1468312718_585588.png)我网上搜的都没用 错误首先是这样的 ``` com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。数据库连接失败 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at ng.jdb.MyConnection.<clinit>(MyConnection.java:21) ``` 但是我打开命令窗口 链接1433可以正常连接,1433也启动了,但还是这样,在线等

Java和sql server2012连接问题

com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190) at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241) at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243) at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at pkg.Main.main(Main.java:19) 连接数据库失败 端口都已经设置好了,但是就是无法连接上,求助。

java连接oracle数据库不能使用主机名

我的虚拟机使用hostname命令显示的是anywhere,然后我查看虚拟机linux系统下的listener.ora文件如下: ``` LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = anywhere)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ``` 然后我的数据库url是:jdbc:oracle:thin:@anywhere:1521:anywhere;但是连接不成功; 我把url改成:jdbc:oracle:thin:@192.168.0.101:1521:anywhere就可以连接.也就是说用ip可以连接,但是用主机名却不行,应该如何配置?

JDBC连接数据库,跟着网上改来改去,还是没能解决

运行结果: 加载驱动成功! 十一月 18, 2015 2:02:59 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: 04507fef-5884-492c-99c2-239b325181ab Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:02:59 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: b59cb8af-995c-47ac-83ea-305da673b90e Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:03:00 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: 83b6ec60-71c4-46d3-a6f1-27c83f33a7ff Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:03:05 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: afae2c34-8f5c-4ec5-92c3-15774149d846 Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:03:06 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 十一月 18, 2015 2:03:10 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: 3f6df96f-3650-41dd-ac2b-e571e5c850e8 Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:03:11 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: 2f7a418c-6961-4ceb-807c-84d299308ed1 Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:03:12 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: 51520155-ee5e-4b8d-956b-9db96111ed23 Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:03:13 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: d2649356-3056-4244-8c35-f1dd2dc67751 Prelogin error: host localhost port 1433 Unexpected response type:72 十一月 18, 2015 2:03:14 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin 警告: ConnectionID:1 ClientConnectionId: ea2915f9-5e42-4735-b5a6-fbfe86029dae Prelogin error: host localhost port 1433 Unexpected response type:72 com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“驱动程序收到意外的登录前响应。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接。该驱动程序只能与 SQL Server 2000 或更高版本一起使用。”。 ClientConnectionId:ea2915f9-5e42-4735-b5a6-fbfe86029dae at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667) at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1654) at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:1464) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1319) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at pkg.Main.main(Main.java:24) SQL Server连接失败!

java连接本地数据库,连接不上。、、、、

public class DatabaseOperation { Connection conn= null; /** * * 取得当前数据库的连接 * * @param connHostName 主机名称或IP Address * @param connPort 连接数据库端口 * @param dbDBAUserName 连接数据库DBA用户名 * @param dbDBAPassword 连接数据库DBA用户密码 * @return */ public Connection connectDatabase(String connHostName,String connPort,String dbDBAUserName,String dbDBAPassword) { try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); String url = "jdbc:sqlserver://" + connHostName + ":" + connPort + ";DatabaseName=master"; conn = DriverManager.getConnection(url, dbDBAUserName, dbDBAPassword); setConn(conn); }catch (Exception ex){ ex.printStackTrace(); setConn(null); } return getConn(); } main方法 public static void main(String[] args) { DatabaseOperation db = new DatabaseOperation(); System.out.println("============"+ db.connectDatabase("localhost", "1433", "sa", "123456"));; } 端口是1433 驱动的包没有错,因为可以连接别人的数据库、 报错如下: [color=red]com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at org.com.sap.db.DatabaseOperation.connectDatabase(DatabaseOperation.java:55) at org.com.sap.db.DatabaseOperation.main(DatabaseOperation.java:229) ============null[/color] 没有高人知道、、指点一二 “Connection refused: connect com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) java 连sql2005出现这个错误时,首先检查是否引用了sql 2005的包; 第二步,看你的sql 2005是否开启了远程访问权限,具体设置如下: 进入“Microsoft SQL Server 2005 ”——“配置工具”——“SQL Server 外围应用配置器” 在进入“MSSQLSERVER"——“DATABASE" Engine”——“远程连接” 选择“本地连接和远程连接(R)"——”同时使用tcp/ip和named pipes(B)" 最后重启sql server 2005 ” 试过了,不是这个问题。。。 [b]问题补充:[/b] 打开了、、、、 但是网络服务器那个,端口号(TCP Port),我不知道怎么填写。 [b]问题补充:[/b] [url]http://dl.iteye.com/upload/attachment/183234/7a07e7f1-8af7-30e5-a303-104a9677d6cb-thumb.jpg[/url] [b]问题补充:[/b] SQL server Configuration Manager 在网络配置中已经是启用TCP/IP了 感觉是当做服务器的时候,端口号没有填、、、 [b]问题补充:[/b] 看见端口都改成1433了。 网络那边是1433 客户端也是1433 [b]问题补充:[/b] C:\Documents and Settings\C5136015>n Active Connections Proto Local Address Fore TCP 0.0.0.0:135 0.0. TCP 0.0.0.0:445 0.0. TCP 0.0.0.0:2180 0.0. TCP 0.0.0.0:2738 0.0. TCP 0.0.0.0:18102 0.0. TCP 10.58.71.159:139 0.0. TCP 10.58.71.159:1244 10.2 TCP 10.58.71.159:1336 10.2 TCP 10.58.71.159:1337 10.2 TCP 10.58.71.159:1341 10.1 TCP 10.58.71.159:1357 10.5 TCP 10.58.71.159:1437 10.5 TCP 10.58.71.159:1711 10.5 TCP 10.58.71.159:1712 10.5 TCP 10.58.71.159:1890 10.5 TCP 10.58.71.159:1894 10.5 TCP 10.58.71.159:1895 10.5 TCP 10.58.71.159:1896 10.5 TCP 10.58.71.159:1897 10.5 TCP 10.58.71.159:14599 0.0. TCP 127.0.0.1:5152 0.0. UDP 0.0.0.0:445 *:* UDP 0.0.0.0:500 *:* UDP 0.0.0.0:1240 *:* UDP 0.0.0.0:4500 *:* UDP 0.0.0.0:6004 *:* UDP 0.0.0.0:18102 *:* UDP 0.0.0.0:18103 *:* UDP 10.58.71.159:123 *:* UDP 10.58.71.159:137 *:* UDP 10.58.71.159:138 *:* UDP 127.0.0.1:123 *:* UDP 127.0.0.1:1025 *:* UDP 127.0.0.1:1068 *:* UDP 127.0.0.1:1126 *:* UDP 127.0.0.1:1315 *:* UDP 127.0.0.1:1328 *:* UDP 127.0.0.1:1342 *:* UDP 127.0.0.1:1447 *:* UDP 127.0.0.1:1562 *:* UDP 127.0.0.1:1666 *:* UDP 127.0.0.1:1698 *:* UDP 127.0.0.1:1750 *:* UDP 127.0.0.1:10000 *:* [b]问题补充:[/b] 1433的端口没有打开,我需要手动打开?还是这个端口已经被占用了 [b]问题补充:[/b] 那怎么打开啊?我刚才添加了1433的端口,要重启么? [b]问题补充:[/b] 重启了还是没有1433端口,按照别人的方法添加了。。。。

idea 搭建ssh框架,配置的数据库ip地址为远程ip,结果请求了本地IP地址,什么原因

用idea整合ssh框架,spring管理hibernate配置文件,数据库配置ip地址为远程服务的IP地址,结果jdbc连接时请求了本地ip地址,具体异常日志如下:09-Jul-2017 09:36:10.193 WARN [RMI TCP Connection(3)-127.0.0.1] org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService HHH000342: Could not obtain connection to query metadata : Access denied for user 'root '@'1.180.235.69' (using password: YES) 09-Jul-2017 09:39:34.591 WARN [http-nio-8080-exec-2] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions SQL Error: 1045, SQLState: 28000 09-Jul-2017 09:39:34.592 ERROR [http-nio-8080-exec-2] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions Access denied for user 'root '@'1.180.235.69' (using password: YES) 09-Jul-2017 09:39:34.598 严重 [http-nio-8080-exec-2] org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler.error Exception occurred during processing request: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1419) at cn.hz.area.dao.TestDao.save(TestDao.java:16) at cn.hz.area.service.TestService.save(TestService.java:16) at cn.hz.area.action.TestAction.execute(TestAction.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) 。。。什么原因!好几天时间找不到问题原因。spring配置hibernate信息如下![图片说明](https://img-ask.csdn.net/upload/201707/09/1499564518_832713.png)

java中用一个Timer类去每个10毫秒访问一次数据库,会不会出现于数据库断开的异常

今天做的测试,为什么会出现这个异常呢? Exception in thread "Timer-0" org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371) at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy6.getId(Unknown Source) at com.test.serviceImpl.UsersServiceImpl.getId(UsersServiceImpl.java:43) at com.test.test.dongtai.run(dongtai.java:34) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353) at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555) ... 10 more Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (到主机 的 TCP/IP 连接失败。 java.net.SocketException: No buffer space available (maximum connections reached?): connect) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) ... 15 more Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.SocketException: No buffer space available (maximum connections reached?): connect at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source) at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221) ... 18 more

使用idea连接远端postgre数据报错

使用idea连接远端postgre数据报错,但是若是使用Navicat Premium却可以正常连接 报错如下: org.postgresql.util.PSQLException: 连线被拒,请检查主机名称和埠号,并确定 postmaster 可以接受 TCP/IP 连线。 at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64) at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:143) at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29) at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21) at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:38) at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:412) at org.postgresql.Driver.connect(Driver.java:280) at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1358) at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1414) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:604) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:878) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:874) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97) at com.zjhcsoft.controller.HVisualSqlResultController.loadData(HVisualSqlResultController.java:95) 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 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at org.postgresql.core.PGStream.<init>(PGStream.java:61) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:110) ... 56 more

拒绝连接:使用docker-compose从应用容器访问Postgres容器

<div class="post-text" itemprop="text"> <p>I'm new to Docker. This project is just for my own understanding. It's likely that I use incorrect terminology and/or am more confused than I think I am. Corrections are gratefully accepted.</p> <p>I'm using two docker images: the official postgres image and my own Go app and Dockerfile. Using <code>docker-compose up</code> I get the <code>connection refused</code> error.</p> <p>I think that there are potentially two different problems: </p> <ul> <li><p>One, the database is not running when the app is trying to connect. </p></li> <li><p>Two, the app is simply using an invalid IP.</p></li> </ul> <p>I have app code that should be giving the database time to start up to address the first potential problem (see code below). Judging by the error message, I don't think I'm even getting that far.</p> <p>I have two services: db-access (that's the Go app) and postgres-db.</p> <p>I have tried using these host names in the app connection string: </p> <ul> <li><p>"localhost", </p></li> <li><p>"postgres-db" (as it's named in the docker-compose.yml), </p></li> <li><p>"0.0.0.0".</p></li> </ul> <p>Using the <code>postgres-db</code> as the hostname:</p> <ul> <li><p>The app container is trying: dial tcp 172.22.0.2:5432.</p></li> <li><p>Postgres is saying: listening on IPv4 address "0.0.0.0", port 5432.</p></li> </ul> <p>In the <code>docker-compose.yml</code> I have tried using these statements: </p> <pre><code>depends_on: - postgres-db </code></pre> <p>and</p> <pre><code>links: - postgres-db </code></pre> <p>I have tried reversing the order of the services in the docker-compose.yml but they appear to start up in the same order either way.</p> <p>When I run the postgres container and the Go app separately I get the expected behavior. To run them separately I'm using these commands:</p> <pre><code>docker run --rm --name postgres-db -e POSTGRES_PASSWORD=docker -d -p 5432:5432 -v /Users/ForeignFood/Development/go/src/github.com/skillitzimberg/docker/volumes/postgres:/var/lib/postgresql/data postgres </code></pre> <p>followed by</p> <p><code>go run basicapi</code></p> <p>I can also run <code>docker-compose up</code>, which gives the connection refused error, then <code>ctrl+C</code>, then run <code>go run basicapi</code> and get the expected behavior.</p> <p>Here are the project files . . .</p> <p>main.go:</p> <pre><code>package main import ( "basicapi/models" "fmt" "net/http" _ "github.com/lib/pq" ) const ( host = "postgres-db" port = 5432 user = "postgres" password = "docker" dbname = "myfirstdb" ) var psqlDatabaseConnectionString = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname) func main() { models.InitDB(psqlDatabaseConnectionString) http.HandleFunc("/users", usersList) http.ListenAndServe(":3000", nil) } func usersList(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { http.Error(w, http.StatusText(405), 405) return } usrs, err := models.AllUsers() if err != nil { fmt.Println(err) http.Error(w, http.StatusText(500), 500) return } for _, usr := range usrs { fmt.Fprintf(w, "%d, %s, %s, %.s ", usr.ID, usr.FirstName, usr.LastName, usr.Email) } } </code></pre> <p>models/db.go:</p> <pre><code>package models import ( "database/sql" "fmt" "log" "time" _ "github.com/lib/pq" ) var db *sql.DB func InitDB(dataSourceName string) { var err error for i := 0; i &lt; 10; i++ { db, err = sql.Open("postgres", dataSourceName) if err != nil { fmt.Println(i) fmt.Println(err) time.Sleep(time.Second * 10) } } if err != nil { log.Panic(err) } if err = db.Ping(); err != nil { log.Panic(err) } fmt.Printf("Connection to database successful! ") } </code></pre> <p>models/users.go:</p> <pre><code>package models import "fmt" type User struct { ID int Age int FirstName string LastName string Email string } func AllUsers() ([]*User, error) { fmt.Println("Got to AllUsers") rows, err := db.Query("SELECT * FROM users") if err != nil { fmt.Println(err) return nil, err } defer rows.Close() users := make([]*User, 0) for rows.Next() { user := new(User) err := rows.Scan(&amp;user.ID, &amp;user.Age, &amp;user.FirstName, &amp;user.LastName, &amp;user.Email) if err != nil { return nil, err } users = append(users, user) } if err = rows.Err(); err != nil { return nil, err } return users, nil } </code></pre> <p>Dockerfile:</p> <pre><code>FROM golang WORKDIR /app COPY ./go.mod ./go.mod COPY ./go.sum ./go.sum RUN go mod download COPY . . RUN go build -o /bin/app CMD [ "app" ] </code></pre> <p>docker-compose.yml</p> <pre><code>services: db-access: build: . depends_on: - postgres-db ports: - "3000:3000" postgres-db: image: postgres volumes: - /Users/ForeignFood/Development/go/src/github.com/skillitzimberg/docker/volumes/postgres:/var/lib/postgresql/data ports: - "5432:5432" environment: POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "docker" POSTGRES_DATABASE: "myfirstdb" </code></pre> <p>Expected results: Navigating to localhost:3000/users shows:</p> <pre><code>1, Someone, Alastname, 2, SomeoneElse, AnotherLastName, etc... </code></pre> <p>Actual results:</p> <ul> <li><p>browser: <code>This site can't be reached</code></p></li> <li><p>terminal: </p></li> </ul> <pre><code>~/ &gt;&gt; docker-compose up Starting basicapi_postgres-db_1 ... done Starting basicapi_db-access_1 ... done Attaching to basicapi_postgres-db_1, basicapi_db-access_1 db-access_1 | 2019/05/17 16:53:54 dial tcp 172.22.0.2:5432: connect: connection refused db-access_1 | panic: dial tcp 172.22.0.2:5432: connect: connection refused db-access_1 | db-access_1 | goroutine 1 [running]: db-access_1 | log.Panic(0xc0000c3f40, 0x1, 0x1) db-access_1 | /usr/local/go/src/log/log.go:333 +0xac db-access_1 | basicapi/models.InitDB(0xc000062120, 0x55) db-access_1 | /app/models/db.go:30 +0x27c db-access_1 | main.main() db-access_1 | /app/main.go:23 +0x3d basicapi_db-access_1 exited with code 2 postgres-db_1 | 2019-05-17 16:53:58.770 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 postgres-db_1 | 2019-05-17 16:53:58.770 UTC [1] LOG: listening on IPv6 address "::", port 5432 postgres-db_1 | 2019-05-17 16:53:58.776 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" postgres-db_1 | 2019-05-17 16:53:58.905 UTC [22] LOG: database system was shut down at 2019-05-17 16:53:23 UTC postgres-db_1 | 2019-05-17 16:53:58.952 UTC [1] LOG: database system is ready to accept connections </code></pre> <p>Thank you for any insights.</p> </div>

插入1w条数据不报错,但是插入2w条数据时候报错,为什么呢?

&nbsp;&nbsp; 我用jdbc做了个定时更新数据库的功能,当插入1w条数据时候没点问题,当插入2w条数据时候,就报连接超时的错误接着,但是程序还是没有挂掉,不知道是什么原因就解? <br />&nbsp;&nbsp;&nbsp; [code='java'] <br />&nbsp;&nbsp;&nbsp; package com.jgre.org; <br /> <br />import java.sql.Connection; <br /> <br />import java.sql.Date; <br />import java.sql.DriverManager; <br />import java.sql.PreparedStatement; <br />import java.sql.ResultSet; <br />import java.sql.SQLException; <br />import java.text.ParseException; <br />import java.text.SimpleDateFormat; <br />import java.util.List; <br /> <br /> <br />public class DB { <br /> //设置 <br /> static int precount=1000; <br /> <br /> public static&nbsp; Connection getConnect() throws Exception{ <br /> &nbsp;&nbsp; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); <br /> &nbsp;&nbsp; //?useUnicode=true&amp;characterEncoding=utf8 <br /> &nbsp;&nbsp; Connection conn= DriverManager.getConnection("jdbc:sqlserver://146.12.62.208:1433;DatabaseName=LHJGXN", "sa", "flying-321"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return conn;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp; } <br /> <br /> public static void free(ResultSet rs,PreparedStatement ps,Connection conn){ <br /> try { <br /> &nbsp; if(rs!=null) rs.close(); <br /> &nbsp; if(ps!=null) ps.close(); <br /> &nbsp; if(conn!=null) conn.close(); <br /> } catch (SQLException e) { <br /> e.printStackTrace(); <br /> } <br /> } <br /> public static void free(PreparedStatement ps,Connection conn){ <br /> try { <br /> &nbsp; if(ps!=null) ps.close(); <br /> &nbsp; if(conn!=null) conn.close(); <br /> } catch (SQLException e) { <br /> e.printStackTrace(); <br /> } <br /> } <br /> //插入数据 <br /> public synchronized int insertObject(List&lt;AJXX&gt; list){ <br /> list=DB.initArray(list); <br /> Connection conn=null; <br /> PreparedStatement ps=null; <br /> try { <br /> conn=DB.getConnect(); <br /> //关闭自动提交 <br /> conn.setAutoCommit(false); <br /> //清空数据库 <br /> ps=conn.prepareStatement("truncate table LHJGXN.dbo.TB_AJXX"); <br /> ps.executeUpdate(); <br /> <br /> long startTime=System.currentTimeMillis(); <br /> String sql="insert into LHJGXN.dbo.TB_AJXX( " + <br /> "AH,NH,ZH,SAXH,AY,LARQ,LAR,CBT,SJCBT, " + <br /> "CBR,AJLB,SPCX,SYCX,SFDA,SFYA,AJSJ,ZZRQ," + <br /> "JARQ, JAFS,GDRQ,DTXP,FDSXDQR,KCSXTS,SXDQR," + <br /> "AJZT,XLABZ)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; <br /> ps=conn.prepareStatement(sql); <br /> for(int i=0;i&lt;list.size();i++){ <br /> System.out.println(i); <br /> AJXX a=list.get(i); <br /> if(a.getAH()!=null&amp;&amp;!a.getAH().equals("")){ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(1, a.getAH()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setInt(2, a.getNH()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(3, a.getZH()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setInt(4, a.getSAXH()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setInt(5, a.getAY()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Date d=new Date(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(tDate(a.getLARQ())==0){ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(6,&nbsp; null); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else{ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(6,&nbsp; new Date(tDate(a.getLARQ()))); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(7, a.getLAR()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(8, a.getCBT()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(9, a.getSJCBT()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(10, a.getCBR()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(11, a.getAJLB()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(12, a.getSPCX()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(13, a.getSYCX()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(14, a.getSFDA()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(15, a.getSFYA()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(16, a.getAJSJ()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(tDate(a.getZZRQ())==0){ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(17, null); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else{ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(17, new Date(tDate(a.getZZRQ()))); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(tDate(a.getJARQ())==0){ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(18, null); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else{ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(18, new Date(tDate(a.getJARQ()))); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(19, getJAFS(a.getJAFS(),conn)); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(tDate(a.getGDRQ())==0){ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(20, null); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else{ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setDate(20, new Date(tDate(a.getGDRQ()))); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setInt(21, a.getDTXP()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(22, a.getFDSXDQR()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setInt(23, a.getKCSXTS()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(24, a.getSXDQR()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(25, a.getAJZT()); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ps.setString(26, a.getXLABZ()); <br /> &nbsp;&nbsp; // ps.executeUpdate(); <br /> &nbsp;&nbsp;&nbsp; ps.addBatch(); <br /> &nbsp;&nbsp;&nbsp; } <br /> //每precount次就批量处理一次 <br /> if((i+1)%precount==0){ <br /> ps.executeBatch(); <br /> //因为不确定总数所以没有去分很多批去执行,我整体做了个批量处理 <br /> &nbsp;&nbsp; } <br /> } <br /> //提交 <br /> //ps.executeBatch(); <br /> <br /> conn.commit(); <br /> ps.clearBatch(); <br /> long endTime=System.currentTimeMillis(); <br /> System.out.println("插入数据时间为:"+(endTime-startTime)+"ms"); <br /> return (int)(endTime-startTime); <br /> } catch (Exception e) { <br /> try { <br /> //如果出现问题就回滚 <br /> conn.rollback(); <br /> } catch (SQLException e1) { <br /> e1.printStackTrace(); <br /> } <br /> e.printStackTrace(); <br /> PrintLog.writeLog("error:"+e.toString()); <br /> }finally{ <br /> DB.free(ps, conn); <br /> } <br /> return -1;&nbsp; <br /> } <br /> //根据案由名称获取案由编号 <br /> public static int getAYBH(String AYMC){ <br /> Connection conn=null; <br /> PreparedStatement ps=null; <br /> ResultSet rs=null; <br /> try { <br /> &nbsp;&nbsp;&nbsp; conn=DB.getConnect(); <br /> ps=conn.prepareStatement("select AYBH from LHJGXN.dbo.TB_AY where AYMC=?"); <br /> ps.setString(1, AYMC); <br /> rs=ps.executeQuery(); <br /> if(rs.next()){ <br /> return rs.getInt(1); <br /> } <br /> } catch (Exception e) { <br /> e.printStackTrace(); <br /> }finally{ <br /> DB.free(rs, ps, conn); <br /> } <br /> return -1; <br /> } <br /> //得到字号 <br /> public static String getZH(String ZHMC){ <br /> Connection conn=null; <br /> PreparedStatement ps=null; <br /> ResultSet rs=null; <br /> try { <br /> conn=DB.getConnect(); <br /> ps=conn.prepareStatement("select ZH from LHJGXN.dbo.TB_ZHXX where ZHMC=?"); <br /> ps.setString(1, ZHMC); <br /> rs=ps.executeQuery(); <br /> if(rs.next()){ <br /> return rs.getString(1); <br /> } <br /> } catch (Exception e) { <br /> e.printStackTrace(); <br /> }finally{ <br /> DB.free(rs, ps, conn); <br /> } <br /> return null; <br /> } <br /> //跟根据结案名称获取JAFS、AJLB、SPCX <br /> public static int getInfo(String cmd,String MC,Connection conn){ <br /> //Connection conn=null; <br /> PreparedStatement ps=null; <br /> ResultSet rs=null; <br /> String sql=null; <br /> if(cmd.equalsIgnoreCase("JAFS")){ <br /> sql="select JAFS from LHJGXN.dbo.TB_JAFS where MC=?"; <br /> }else if(cmd.equalsIgnoreCase("AJLB")){ <br /> sql="select AJLB from LHJGXN.dbo.TB_JAFS where MC=?"; <br /> }else if(cmd.equalsIgnoreCase("SPCX")){ <br /> sql="select SPCX from LHJGXN.dbo.TB_JAFS where MC=?"; <br /> } <br /> try { <br /> conn=DB.getConnect(); <br /> ps=conn.prepareStatement(sql); <br /> ps.setString(1, MC); <br /> rs=ps.executeQuery(); <br /> if(rs.next()){ <br /> return rs.getInt(1); <br /> } <br /> } catch (Exception e) { <br /> e.printStackTrace(); <br /> }finally{ <br /> DB.free(rs, ps, conn); <br /> } <br /> return -1; <br /> } <br /> public static long tDate(String d){ <br /> SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); <br /> &nbsp;&nbsp; try { <br /> &nbsp;&nbsp; if(d!=null&amp;&amp;!d.equals("")){ <br /> java.util.Date date=sdf.parse(d); <br /> return date.getTime();} <br /> } catch (ParseException e) { <br /> e.printStackTrace(); <br /> } <br /> return 0; <br /> } <br /> public static String getJAFS(String jafs,Connection conn){ <br /> if(jafs!=null&amp;&amp;!jafs.trim().equals("")){ <br /> // Connection conn=null; <br /> PreparedStatement ps=null; <br /> ResultSet rs=null; <br /> try { <br /> conn=DB.getConnect(); <br /> ps=conn.prepareStatement("select JAFS from LHJGXN.dbo.TB_JAFS where MC=?"); <br /> ps.setString(1, jafs); <br /> rs=ps.executeQuery(); <br /> if(rs.next()){ <br /> return rs.getString(1); <br /> } <br /> } catch (Exception e) { <br /> e.printStackTrace(); <br /> }finally{ <br /> DB.free(rs,ps, conn); <br /> } <br /> } <br /> return null; <br /> } <br /> public static List&lt;AJXX&gt; initArray(List&lt;AJXX&gt; d){ <br /> while(d!=null&amp;d.size()&gt;0&amp;d.size()%precount!=0){ <br /> AJXX a=new AJXX(); <br /> d.add(a); <br /> } <br /> System.out.println("格式化后的数据长度:"+d.size()); <br /> return d; <br /> } <br /> <br />} <br /> <br /> <br />&nbsp;&nbsp; <br /> <br />&nbsp; 然后报的错误是这样的 <br />&nbsp; <pre name="code" class="java"> 22238 22239 22240 com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.BindException: Address already in use: connect at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at com.jgre.org.DB.getConnect(DB.java:22) at com.jgre.org.DB.getJAFS(DB.java:226) at com.jgre.org.DB.insertObject(DB.java:98) at com.jgre.org.PickTask$1.run(TimerUse.java:120) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.rollback(Unknown Source) at com.jgre.org.DB.insertObject(DB.java:130) at com.jgre.org.PickTask$1.run(TimerUse.java:120) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerStatement.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setString(Unknown Source) at com.jgre.org.DB.insertObject(DB.java:98) at com.jgre.org.PickTask$1.run(TimerUse.java:120) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) 2012-12-04 00:54:08 00:54 2012-12-04 00:55:08 00:55 2012-12-04 00:56:08 00:56 </pre> <br /> <br />&nbsp;&nbsp;&nbsp; 求遇到过类似情况的,麻烦告诉下解决办法,急救,谢谢!!

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你期望月薪4万,出门右拐,不送,这几个点,你也就是个初级的水平

先来看几个问题通过注解的方式注入依赖对象,介绍一下你知道的几种方式@Autowired和@Resource有何区别说一下@Autowired查找候选者的...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版(进大厂必备)

正确选择比瞎努力更重要!

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

字节跳动面试官竟然问了我JDBC?

轻松等回家通知

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

立即提问
相关内容推荐