1
Java에서 최대 절전 모드를 사용하는 방법을 배우려하고 있으며 다운로드 한 예제를 실행하는 데 문제가 있습니다. 다음 코드를 포함 :Java SQL "구문 오류 또는 액세스 위반"
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatetutorial</property>
<property name="hibernate.connection.username">web</property>
<property name="hibernate.connection.password">web</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
과 (http://www.roseindia.net/hibernate/runninge-xample.shtml에서 다운로드) : 주요 기능 :
이Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
....
at org.hibernate.persister.entity.BasicEntityPersister.insert...
**Caused by: java.sql.SQLException: Syntax error or access violation message from server: "Access denied for user 'web'@'localhost' to database 'hibernatetutorial'"**
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
...
at org.hibernate.connection.DriverManagerConnectionProvider.getConnectio...
내 구성 파일에 다음 코드를 포함 나는 다음과 같은 오류를 받고 있어요
public static void main(String[] args) {
Session session = null;
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("[email protected]");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
나는 필요한 모든 권한을 가진 새로운 "웹"사용자를 만들었습니다 :
CREATE USER 'web'@'localhost' IDENTIFIED BY 'web';
GRANT ALL PRIVILEGES ON hibernatetutorial.* TO [email protected] IDENTIFIED BY 'web';
그리고 "hibernatetutorial"데이터베이스를 만들었습니다. 내가 뭘 잘못하고 있는지 알 겠어? 나는 이것을 디버깅하는 방법조차 모른다.
감사합니다, 리
를 잘합니다. 그것을 변경 한 후에도 오류가 계속 발생하지만 ("루트"사용자와 먼저 시도하고 동일한 오류가 발생했다면 사용자를 "웹"으로 변경하여 권한 문제는 아니지만 잘못된 구문을 사용했습니다.(). – user429400