jdbc连接-socket连接

发布于 2024-11-03 21:03:20 字数 617 浏览 0 评论 0原文

几天前,我的网站崩溃了并向我显示以下错误:

java.lang.NoClassDefFoundError:可以 不初始化类 com.omicc.hibernate.util.HibernateUtil

因此,我向托管公司询问了他们可能所做的任何更改。他们解决了这个问题并告诉我使用 JDBC 连接而不是套接字连接。 我将 hibernate 和 c3p0 与 MySQL 一起使用,据我所知,它们使用 JDBC 连接。

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

那么大家知道他在说什么吗? :D(是的,他现在没有回答!)

已编辑>>>>

解决了!所以这就是我所做的 我将我的休眠从休眠从 3.5.0 升级到 3.6.1 新的 hibernate 需要 hibernate-jpa-2.0-api-1.0.0.Final.jar 和 slf4j-simple1.6.1 。 并解决了问题。 我认为托管公司更新了他们的 hibernate.jar 并且导致了一些参考问题。

A few days ago my website crashed and showed me this error:

java.lang.NoClassDefFoundError: Could
not initialize class
com.omicc.hibernate.util.HibernateUtil

So I asked the hosting company about any changes that they may have made. They fixed the problem and told me to use JDBC connections instead of socket connections.
I am using hibernate and c3p0 with MySQL and as far as I know they use JDBC connections.

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

So do any of you guys know what he was talking about? :D (and yes he is not answering now!)

EDITED>>>>

Solved!, so here is what i did
i upgraded my hibernate from hibernate from 3.5.0 to 3.6.1
and new hibernate required hibernate-jpa-2.0-api-1.0.0.Final.jar and slf4j-simple1.6.1 .
and problem solved.
i think that the hosting company updated their hibernate.jar and it caused some reference problems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠佳期 2024-11-10 21:03:20

重写 HibernateUtil,使其不会在静态块中实例化。相反,使其成为具有同步 getInstance 的单例。然后

private static SessionFactory cache;

synchronized SessionFactory getInstance() throws SQLException {

if (cache != null) return cache;

// try/catch and rethrow SQLException
try {
Class.forName("com.mysql.jdbc");
} Exception (e) {
throw new SQLException(e);
}
// Test connection with JDBC
// Create a non connection pooled raw connection, try/finally close it
// throw SQL Exception if it fails
testMe()

// finally create the sessionFactory
.... build your Configuration object
.... then 
try {
SessionFactory me = ....buildSessionFactory
} catch (RuntimeException e) {
throw new SQLException(e);
}
cache = me;
return cache;

}

一些评论:有些人会更喜欢未经检查的异常,这很好。
我喜欢执行一次原始连接的原因是,在启动时,如果 SQL Server 恰好完成,它往往会减少连接池/休眠时间。一旦它们成功初始化,我就没有遇到恢复问题。但这是个人品味的问题,您也可以跳过 testMe()。

重点是这样您将看到异常发生,我向您预测这将清楚地暗示与托管公司的连接:)

Rewrite your HibernateUtil so it doesn't instantiate in a static block. Instead make it a singleton with a synchronized getInstance. Then

private static SessionFactory cache;

synchronized SessionFactory getInstance() throws SQLException {

if (cache != null) return cache;

// try/catch and rethrow SQLException
try {
Class.forName("com.mysql.jdbc");
} Exception (e) {
throw new SQLException(e);
}
// Test connection with JDBC
// Create a non connection pooled raw connection, try/finally close it
// throw SQL Exception if it fails
testMe()

// finally create the sessionFactory
.... build your Configuration object
.... then 
try {
SessionFactory me = ....buildSessionFactory
} catch (RuntimeException e) {
throw new SQLException(e);
}
cache = me;
return cache;

}

Some comments: some people will prefer an unchecked exception, which is fine.
The reason I like doing the raw connection once is that on startup it tends to bollix up connection pool/hibernate less if the SQL Server happens to be done. Once they initialize successfully I've not had recovery issues. But that's a personal taste thing, and you could skip testMe() as well.

Point is this way you will SEE the Exception occurring, and I predict to you it will clearly implicate the connection to the hosting company :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文