![](/img/trans.png)
[英]I am getting an error, while adding DesignGridLayout to my register form. Please help me with this
[英]I am getting error for my first hibernate program, please help me to resolve the erros
错误:
log4j:WARN找不到记录器的附加程序(org.hibernate.cfg.annotations.Version)。 log4j:WARN请正确初始化log4j系统。 线程“主”中的异常org.hibernate.exception.GenericJDBCException:无法在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)的org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)处打开连接)在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)在org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java: 420)位于org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)位于org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)位于org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java :57)在org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)在org.koushik.hibernate.HibernateTest.main(HibernateTest.java:20)在由:org.postgresql.util.PSQLException:FATAL: org.pos中不存在数据库“ 5432 / hibernatedb” org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:207)处的tgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:691)在org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java: 65)在org.postgresql.Driver.makeConnection(Driver.java:415)在org.postgresql.Driver.makeConnection(Driver.java:415)在org.postgresql.Driver.make(PgConnection.java:159)在Java org.hibernate.jdbc.ConnectionManager.openConnection上的org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)上的java.sql.DriverManager.getConnection(未知源)上的.sql.DriverManager.getConnection(未知源) ConnectionManager.java:417)...还有5个
码
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration SYSTEM "hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost/5432/hibernatedb</property>
<property name="connection.username">postgres</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> -->
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping class="org.javabrains.koushik.dto.UserDetails" />
<!-- <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/> -->
</session-factory>
</hibernate-configuration>
UserDetails.java
package org.javabrains.koushik.dto;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class UserDetails {
@Id
private int userID;
private String userName;
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
HibernateTest.java
package org.koushik.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.javabrains.koushik.dto.UserDetails;
public class HibernateTest {
public static void main(String[] args) {
UserDetails user = new UserDetails();
user.setUserID(1);
user.setUserName("First user");
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session =sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
}
}
似乎您的连接网址有误。 不是吗
jdbc:postgresql://localhost:5432/hibernatedb
?
检查您的连接URL路径,它应该像这样:
<property name="connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
如果这不起作用,请注意,在PostgreSQL的情况下,通常使用端口5432(如果可用)。 如果不是,大多数安装程序将选择下一个可用端口,通常为5433。因此,您可以输入以下属性
<property name="connection.url">jdbc:postgresql://localhost:5433/hibernatedb</property>
如果您仍然无法弄清楚,请在您的堆栈跟踪中阅读此行,您可能会知道@RemyG试图说明的内容:
org.postgresql.util.PSQLException: FATAL: database "5432/hibernatedb" does not exist at
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.