2017-01-08 15 views
0

Image contains the JARS files which I already have.これはこれは私のDTOクラス初めてのHibernateクラスの持つ注釈

package com.app.hibernate; 

import java.io.Serializable; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Id; 
import javax.persistence.Table; 

@Entity 
@Table(name = "paytm_table") 

public class PaytmDTO implements Serializable 
{ 
    @Id 
    @Column(name="mob_num") 
    private int mobileNumber; 

    @Column(name="amount") 
    private int amount; 

    @Column(name="email_id") 
    private String emailId; 

    @Column(name="OTP") 
    private int OTP; 

    public PaytmDTO() { 

    } 

    public int getMobileNumber() { 
     return mobileNumber; 
    } 

    public void setMobileNumber(int mobileNumber) { 
     this.mobileNumber = mobileNumber; 
    } 

    public int getAmount() { 
     return amount; 
    } 

    public void setAmount(int amount) { 
     this.amount = amount; 
    } 

    public String getEmailId() { 
     return emailId; 
    } 

    public void setEmailId(String emailId) { 
     this.emailId = emailId; 
    } 

    public int getOTP() { 
     return OTP; 
    } 

    public void setOTP(int oTP) { 
     OTP = oTP; 
    } 

} 

である私のhibernate.cfg.xmlファイル

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 
     <property name="connection.username">root</property> 
     <property name="connection.password">root</property> 
     <property name="connecton.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="connection.url">jdbc:mysql://localhost:3306/hibernate_db</property> 
     <property name="show_sql">true</property> 
    </session-factory> 
</hibernate-configuration> 

である。これは私のDAOクラスです

package com.app.hibernate; 

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.Transaction; 
import org.hibernate.cfg.Configuration; 

public class PaytmDAO 
{ 
    public static void main(String[] args) 
    { 
     //Create Object of DTO 
     PaytmDTO dto=new PaytmDTO(); 

     //Set the DTO values using Setter method 
     dto.setAmount(239); 
     dto.setEmailId("[email protected]"); 
     dto.setMobileNumber(941478859); 
     dto.setOTP(8965); 

     //Create Object of Configuration 
     Configuration config=new Configuration(); 
     config.configure(); 
     config.addAnnotatedClass(PaytmDTO.class); 

     //Create object of 2nd Component SessionFactory 
     SessionFactory sf=config.buildSessionFactory(); 

     //Get a Session (3rd Component) 
     Session sess=sf.openSession(); 
     sess.save(dto); 

     Transaction tx=sess.beginTransaction(); 
     tx.commit(); 

    } 

} 

そして、コンソールでこれらのエラーが発生しています

Jan 08, 2017 11:37:33 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init> 
INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) 
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) 
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724) 
    at com.app.hibernate.PaytmDAO.main(PaytmDAO.java:27) 
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling DriverManager#getConnection 
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115) 
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:101) 
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123) 
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionCreator.makeConnection(DriverManagerConnectionCreator.java:37) 
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58) 
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:106) 
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:40) 
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:19) 
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:138) 
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:110) 
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:74) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234) 
    ... 14 more 
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/hibernate_db 
    at java.sql.DriverManager.getConnection(Unknown Source) 
    at java.sql.DriverManager.getConnection(Unknown Source) 
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionCreator.makeConnection(DriverManagerConnectionCreator.java:34) 
    ... 29 more 

私は欠けている場所を教えてください。私のDBのユーザー名とパスワードはrootです。これは私の最初のHibernateプログラムであり、私は自分のlibの下にすべてのjarファイルを貼り付け、またbuildPathを使っています。

答えて

0

それはによって引き起こさ

かなり明確言わない:ます。java.sql.SQLException:見つかりませ最適なドライバ...

おそらくMySQLのコネクター・ライブラリーが欠落しています。あなたはMavenを使用している場合は、あなたのpom.xml

<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>6.0.5</version> <!-- or whatever version is suitable --> 
    <scope>runtime</scope> 
</dependency> 

を追加します。そうでなければ、.jarをダウンロードすることができます。here

+0

** MySQLコネクタを追加しました。 libフォルダの下にある追加されたJARSを添付しました** –

+0

私は私のjarファイルのイメージを追加しました。見てください。 –

関連する問題