简体   繁体   English

jdbc连接-插座连接

[英]jdbc connection - socket connection

A few days ago my website crashed and showed me this error:几天前,我的网站崩溃并显示此错误:

java.lang.NoClassDefFoundError: Could not initialize class com.omicc.hibernate.util.HibernateUtil java.lang.NoClassDefFoundError: 无法初始化 class com.omicc.ZCB1F0028.EEBF50174D6EFA9

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.他们解决了这个问题并告诉我使用 JDBC 连接而不是套接字连接。 I am using hibernate and c3p0 with MySQL and as far as I know they use JDBC connections.我将 hibernate 和 c3p0 与 MySQL 一起使用,据我所知,他们使用 JDBC 连接。

<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!) :D(是的,他现在没有回答!)

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. 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.我认为托管公司更新了他们的 hibernate.jar 并引起了一些参考问题。

Rewrite your HibernateUtil so it doesn't instantiate in a static block.重写您的 HibernateUtil,使其不在 static 块中实例化。 Instead make it a singleton with a synchronized getInstance.而是将其设为具有同步 getInstance 的 singleton。 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.我喜欢做一次原始连接的原因是,如果 SQL 服务器碰巧完成,它会在启动时减少连接池/休眠。 Once they initialize successfully I've not had recovery issues.一旦他们成功初始化,我就没有恢复问题。 But that's a personal taste thing, and you could skip testMe() as well.但这是个人喜好问题,您也可以跳过 testMe()。

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:)重点是这样你会看到异常发生,我预测你会清楚地暗示与托管公司的连接:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM