大家好我正在使用Hibernate + Struts2 + Tomcat6 + Mysql作为我的J2EE框架.我一直在使用hibernate的内置连接池机制,但结果证明mysql在8小时后关闭它的连接是有问题的.无论如何,我google了一下,发现我应该通过JNDI数据源获得我的连接,但我无法就此达成一个完整的教程.我应该采取什么措施呢?请给我足够的细节,我对此有点新意.这是我的hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/hposg?characterEncoding=UTF-8
</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.max_fetch_depth">3</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_size">25</property>
<property name="hibernate.c3p0.min_size" >3</property>
<property name="hibernate.c3p0.max_statement">0</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- Mapping files -->
<mapping resource="com/hposg/hibernate/resources/Player.hbm.xml"/>
<mapping resource="com/hposg/hibernate/resources/Game.hbm.xml"/>
...
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
我也尝试了这个,但它没有成功:在WebContent/META-INF中创建一个context.xml,包含:
<Context path="" docBase="../RSGames" debug="0" …
Run Code Online (Sandbox Code Playgroud) 我一直在努力测试Java Web应用程序(JSP + Tomcat6 + Struts2 + Hibernate + mysql),而且我得到的结果并不值得吹嘘!所以我将tomcat版本升级到7,哇!我得到的请求数/秒比以前好5倍.
那么赐教,tomcat6和tomcat7的性能有这么大差异吗?或者我的配置和东西有问题?
此代码应该向struts操作发送两个参数:
<s:url id="loadReportsForAPageInitial" value="/loadReportsForAPage.action" >
<s:param name="reportsCount_hidden" value="3"></s:param>
<s:param name="pageNumber_hidden" value="1"></s:param>
</s:url>
<sj:div href="%{loadReportsForAPageInitial}">
</sj:div>
Run Code Online (Sandbox Code Playgroud)
问题是只有第一个参数的值被发送到struts动作而第二个参数是null!我改变了两个参数的位置,再次只有第一个参数很好.
是否可以通过as:url标记传递多个参数?
UPDATE
这是url标记的呈现方式:
<script type='text/javascript'>
jQuery(document).ready(function () {
var options_div_1179027906 = {};
options_div_1179027906.jqueryaction = "container";
options_div_1179027906.id = "div_1179027906";
options_div_1179027906.href = "/FAP/loadReportsForAPage.action";
options_div_1179027906.hrefparameter = "reportsCount_hidden=3&pageNumber_hidden=1";
jQuery.struts2_jquery.bind(jQuery('#div_1179027906'),options_div_1179027906);
});
Run Code Online (Sandbox Code Playgroud) 我在我的页面中使用jqGrid,我修改了ui.jqgrid.css文件以包装列标题,如下所示:
.ui-jqgrid tr.jqgrow td {
white-space: normal !important;
}
.ui-th-column,.ui-jqgrid .ui-jqgrid-htable th.ui-th-column{
white-space:normal;
}
Run Code Online (Sandbox Code Playgroud)
它适用于所有浏览器,但IE!我试过IE7和IE8,问题依然存在.
我有一个Java Web应用程序,它接收一些实时事件并将它们推送到用户界面层.我想记录所有感知事件,因为信息量很大,我更喜欢使用NoSQL数据库.
我为此设置了一个mongodb,它为每个事件插入一个文档.问题是这种方法(每个事件的磁盘访问)大大减慢了整个过程.
那么,在这种情况下,我可以采取什么方法?mongodb中有哪些选项(例如批量插入,异步插入,缓存......)?会切换到其他一些NoSQL数据库实现有所作为吗?这里的最佳做法是什么?
我们在 SQL Server 中有这个用户定义的表类型:
CREATE TYPE [dbo].[INITVALS_MSG] AS TABLE(
[SDate] [decimal](8, 0) NOT NULL,
[EDate] [decimal](8, 0) NOT NULL,
[PlantCode] [nvarchar](10) NOT NULL,
[LoadType] [nchar](8) NOT NULL,
[Asset] [bigint] NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
以及一个将该表作为输入的存储过程:
ALTER PROCEDURE [dbo].[RegisterInitAssets]
@initmsg INITVALS_MSG ReadOnly
AS
BEGIN
...
Run Code Online (Sandbox Code Playgroud)
现在,我需要从 java 调用这个过程。有可能做这样的事情吗?JDBC 支持吗?
--------编辑我在java中有一个对应的类用于该类型:
public class DBInitialAsset {
private Integer sDate;
private Integer eDate;
private String plantCode;
private String loadType;
private Integer asset;
public DBInitialAsset() {
}
}
Run Code Online (Sandbox Code Playgroud) 我得到以下查询:
db.getCollection('Messages').aggregate(
{
$match :
{
"header.MessageType" : { $in: ["04"] },
}
},
{
$project:
{
_id: '$_id',
header: '$header',
content: '$content',
q0: { $arrayElemAt: [ "$content.Changes", 0 ] },
q1: { $arrayElemAt: [ "$content.Changes", 1 ] },
q2: { $arrayElemAt: [ "$content.Changes", 2 ] },
q3: { $arrayElemAt: [ "$content.Changes", 3 ] },
q4: { $arrayElemAt: [ "$content.Changes", 4 ] },
q5: { $arrayElemAt: [ "$content.Changes", 5 ] },
}
},
{
$match :
{
"q0":"1"
}
}, …
Run Code Online (Sandbox Code Playgroud) 我得到了这个 Java Web 应用程序,它恰好与 SQL Server 数据库进行了过多的通信。我想决定如何以有效的方式管理与该数据库的连接。我想到的第一个选项是使用第三方连接池。我选择了C3P0和DBCP,并准备了一些测试用例来比较这些方法,如下所示:
无池化:
public static void main(String[] args) {
long startTime=System.currentTimeMillis();
try {
for (int i = 0; i < 100; i++) {
Connection conn = ConnectionManager_SQL.getInstance().getConnection();
String query = "SELECT * FROM MyTable;";
PreparedStatement prest = conn.prepareStatement(query);
ResultSet rs = prest.executeQuery();
if (rs.next()) {
System.out.println(i + ": " + rs.getString("CorpName"));
}
conn.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Finished in: "+(System.currentTimeMillis()-startTime)+" milli secs");
}
Run Code Online (Sandbox Code Playgroud)
二氯苯酚:
public static …
Run Code Online (Sandbox Code Playgroud)