English 中文(简体)
jdbc 连接——电话连接
原标题:jdbc connection - socket connection

几天前,我的网站坠毁,向我展示了这一错误:

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.

问题回答

您 直至此,它就在一个静态的路障中即时。 相反,使它成为一个单一州,同时实现一体化。 之后

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 :)





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签