为什么我们的连接池关闭?(Why is our Connection Pool Closing?)
我们有一台运行在Windows Server 2008 R2上运行的Apache Tomcat 7.0.54上的JSF2.0网络服务器。 我们在运行的计算机上安装了2台SQL服务器,另一台托管了我们的库存软件。 我们网页的一部分是验证PartNumbers被添加。 在阅读了Connection Pools是与SQL服务器交流的最佳实践之后,我们创建了一个并用它来对我们的库存软件进行一些验证。
因为我想要一种方法来检查连接池的健康状况,我使用ViewScoped支持bean创建了一个测试页面,验证2个已知的良好部件号。 今天是本周第二次出现错误消息“连接已关闭”。 由于我是新手,并且似乎无法找到关于此的任何信息,所以我对我们没有设置正确的东西感到困惑。 我刚刚重置了Apache服务器,并且它已备份并正在运行。 所以..要创建我们的连接池,我在应用程序的META-INF / context.xml中添加了一些代码。
<Resource type="javax.sql.DataSource" name="jdbc/FOODB" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://Foobar\Inventory;databaseName=FooInventory;user=johnDoe;password=astrongpassword;" />
我必须使用ConnectionPool的基本概念是我有一个名为SqlAccessCommand的接口。 它或多或少是一种适配器模式。 在我的测试页面中,我使用RunUnsafe方法,以便可以显示错误消息。 所以这里是RunUnsafe方法。
protected static DataSource getDataSource() throws NamingException { Context context = (Context) new InitialContext().lookup("java:/comp/env"); DataSource ds = (DataSource) context.lookup("jdbc/FOODB"); return ds; } public static <T> T RunUnsafe(SqlAccessCommand<T> command) throws NamingException, SQLException { try { DataSource ds = getDataSource(); try (Connection connection = ds.getConnection(); PreparedStatement statement = connection.prepareStatement(command.getSqlStatement())) { command.prepareStatment(statement); try (ResultSet rs = statement.executeQuery()) { return command.getResults(rs); } } } catch (NamingException | SQLException e) { Logger.getLogger(AOSqlInformationHolder.class.getName()).log(Level.SEVERE, null, e); throw e; } }
正如你所看到的,我使用了试用资源,它应该在使用后关闭我的连接,无论如何。 就像try / catch /最后一样,只是更清洁(IMO)。 所以当我的连接打开时,这工作得很好。 到目前为止2x现在我不得不重新启动服务器(因为我不知道如何以其他方式重新打开连接)我错过了什么? 如果需要拼图的更多部分给我留言,我会发布我能做的。 谢谢。
编辑
只是看了看日志文件,今天早上抛出了这个异常
com.microsoft.sqlserver.jdbc.SQLServerException:由peer重置的连接:套接字写入错误
根据迄今为止的评论,它被假定为暂停。 这个错误信息仍然指向那个方向吗?
We have a JSF2.0 webserver running on Apache Tomcat 7.0.54 running on Windows Server 2008 R2. We have 2 SQL servers on on the machine this is running on, and another which hosts our inventory software. One part of our webpage is validation of PartNumbers being added. After reading that Connection Pools are best practice for talking with SQL servers we created one and used it for some of the validation against our inventory software.
Because I wanted a way to be able to check the health of the connection pool I created a test page with a ViewScoped backing bean that validates 2 known good part numbers. Today is the second time this week that the error message "Connection is closed" appeared. Since i'm new to conenction pools and can't seem to find any information regarding this I'm baffled as to what we didn't setup right. I just now reset the Apache server and it is back up and running. So.. to create our connection pool I added some code to the app's META-INF/context.xml.
<Resource type="javax.sql.DataSource" name="jdbc/FOODB" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://Foobar\Inventory;databaseName=FooInventory;user=johnDoe;password=astrongpassword;" />
The basic concept that I have to use the ConnectionPool is that I have an interface called SqlAccessCommand. It is more or less an adapter pattern. In my test page i use the RunUnsafe method so that I can display the error message. So here is the RunUnsafe method.
protected static DataSource getDataSource() throws NamingException { Context context = (Context) new InitialContext().lookup("java:/comp/env"); DataSource ds = (DataSource) context.lookup("jdbc/FOODB"); return ds; } public static <T> T RunUnsafe(SqlAccessCommand<T> command) throws NamingException, SQLException { try { DataSource ds = getDataSource(); try (Connection connection = ds.getConnection(); PreparedStatement statement = connection.prepareStatement(command.getSqlStatement())) { command.prepareStatment(statement); try (ResultSet rs = statement.executeQuery()) { return command.getResults(rs); } } } catch (NamingException | SQLException e) { Logger.getLogger(AOSqlInformationHolder.class.getName()).log(Level.SEVERE, null, e); throw e; } }
As you can see i use the try with resources which is supposed to close my connections after use no matter what. Much like the try/catch/finally does, just cleaner (IMO). so when my connection is open this works just fine. so far 2x now I have had to restart the server (since I don't know how to re-open said connection any other way) what am I missing? If more parts of the puzzle are needed leave me a comment and I will post what I can. Thank you.
EDIT
just looked into the log files and this morning there was this exception thrown
com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error
According to the comments thus far it was assumed a timeout. Does this error message still point in that direction?
原文:https://stackoverflow.com/questions/27024861
最满意答案
在您的MYSQL查询中:
SELECT * FROM `yourTableName` WHERE `eventDate` >= $startDate AND `eventDate` <= $endDate
PS:我不确定引用查询中的变量的引号。
PPS:从不使用*来选择列,始终只选择您需要的列。 我在这里使用它是因为我不知道列的名称
I ended up doing my checking in PHP and print a new row only when a different date is detected.
Codes below in case it serves someone's needs in future.
<?php $currentPrintDay = 0; $currentPrintMonth = 0; $currentPrintYear = 0; echo "<table>" foreach($reservationsToShow as $row): // get day, month, year of this entry $timestamp = strtotime($row['timestamp']); $day = date('d', $timestamp); $month = date('m', $timestamp); $year = date('Y', $timestamp); // if it does not match the current printing date, assign it to the current printing date, // assign it, print a new row as the header before continuing if($day != $currentPrintDay || $month != $currentPrintMonth || $year != $currentPrintYear) { $currentPrintDay = $day; $currentPrintMonth = $month; $currentPrintYear = $year; echo "<tr>" . "<td colspan='100%'>". date('d-m-Y', $timestamp) . "</td>" . "</tr>"; } // continue to print event details from here on... ?>
相关问答
更多-
完整日历截断标题(full calendar truncate title)[2023-06-26]
是。 我想你可以做到这一点。 以下是示例代码。 您必须使用两个事件eventRender和eventAfterAllRender。 或者您也可以隐藏eventAfterAllRender中的元素。 eventRender: function (event, element, view) { if( window.screen.width < 300 ) { $('.fc-event-title').hide(); $('.fc-event-time').hide(); ... -
我认为你正在推翻这一项。 如果您只需要访问公共日历上的活动,就可以在不调用Google日历API和所有附加复杂性的情况下执行此操作。 每个公开的 Google日历都有一个iCal供稿,可以通过特定的URL进行查看,通常采用以下形式: http://www.google.com/calendar/ical/{OWNER}/public/basic.ics 其中{OWNER}是日历所有者的URL编码电子邮件地址。 您可以通过查看日历设置并滚动到“日历详细信息”选项卡的底部来查找特定的URL。 I think ...
-
PHP,MySql - 旧日历不显示每月第10天以下的事件(PHP, MySql - Old Calendar not showing events below day 10 of each month)[2023-09-03]
就像你说的那样,你需要一个月和日的前导零。 对我来说,它看起来就像这条线 $event_day = $year.'-'.$month.'-'.$list_day; 是导致错误的原因。 2014年10月9日将使$ event_day成为2014-10-9,而不是2014-10-09。 你可以试试 $event_day = sprintf('%d-%02d-%02d', $year, $month, $list_day); 要么 $event_day = date('Y-m-d', mktime(0,0,0 ... -
你需要添加一个DotSpan。 此外,我不得不阅读图书馆文档因为我自己没有使用过它。 第1步:在Fragment类中 private List
events = new ArrayList<>(); 第2步 : private void makeJsonObjectRequest() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.g ... -
在您的MYSQL查询中: SELECT * FROM `yourTableName` WHERE `eventDate` >= $startDate AND `eventDate` <= $endDate PS:我不确定引用查询中的变量的引号。 PPS:从不使用*来选择列,始终只选择您需要的列。 我在这里使用它是因为我不知道列的名称 I ended up doing my checking in PHP and print a new row only when a different date is d ...
-
Php日历事件(Php calendar of events)[2023-12-26]
这是我的解决方案。 我在文章中添加了一个日期ID:23. May23.-31.05 h< ...我认为easyphpcalendar可能就是你所需要的。 I think I found what I need here php calendar script经过谷歌的大量搜索,我认为我找到了解决方案,至少在我的例子中工作: if($calendar->accesslevel->value != "read" && $calendar->accesslevel->value != "freebusy" && $calendar->accesslevel->value != "none") $html .= "- " . $calendar->title->text ."
我能够让这个工作,我认为这与日期/时间格式有关,而不是任何事情。 $event_day = date('Y-m-d',strtotime($year.'-'.$month.'-'.$list_day)); foreach($events as $event) { if ($event[ArrDate] == $event_day) { $cntry = $event[CountryID]; ...您需要将$calendarList作为Object获取,而不是像当前代码那样获取Array。 使用 $client->setUseObjects(true); 就在此之前 $service = new apiCalendarService($client); 说明: $events = $cal->events->listEvents('rtparies@gmail.com'); 返回一个数组。 如果您不需要对象进行进一步处理,那就没问题。 由于您需要一个对象,因此需要将对象的使用设置为true: ...- 项目中用连接池管理Connection,connection用完后还关闭吗?
- JDBC系列教程之十五:数据源和连接池
- The connection to adb is down, and a severe error has occured.
- 使用连接池操作redis
- Oceanus连接池的相关配置
- httpclient 关闭连接池中无效连接
- 使用集群式的连接池操作redis
- httpclient 使用连接池管理http请求对象
- There is already an open DataReader associated with this Connection which must be closed first
- tomcat连接池和mysql数据库的中文乱码
- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)