Results 1 to 3 of 3
  1. #1
    The Vicky is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default Please help me need urgent help on JPA connection

    Hi,
    In my current assignment I'm trying to connect a remote MS Access database using JPA. But I'm not able to connect to database in my desktop itself .

    Below is my code let me know if I'm doing something wrong.

    persistence.xml
    =========
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.ejb.cmp3.Ent it yManagerFactoryProvider</provider>
    <class>Dao.UserDetails</class>
    <properties>
    <property name="toplink.jdbc.user" value=""/>
    <property name="toplink.jdbc.password" value=""/>
    <property name="toplink.jdbc.url" value="jdbcdbc:ds_userdsn"/>
    <property name="toplink.jdbc.driver" value="sun.jdbc.odbc.JdbcOdbcDriver"/>
    <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
    </persistence-unit>
    </persistence>


    UserAuth.java
    =========
    package DaoLayer;

    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;

    import Dao.UserDetails;

    public class UserAuth {

    public static void main(String[] args) {
    String UserId="system1";
    String password="t12121";
    EntityManager em = null;
    try {
    EntityManagerFactory emf=Persistence.createEntityManagerFactory("hello-world");
    em = emf.createEntityManager();
    em.getTransaction().begin();
    UserDetails us=new UserDetails();
    us.setUserId(UserId);
    us.setPassword(password);
    em.persist(us);
    em.getTransaction().commit();
    em.close();
    System.out.println("Persisted");
    }
    finally{
    if(em != null){
    System.out.println("hi");

    }
    }


    }
    }

    * ds_userdsn is the user dsn created
    * Also Class of the object to be persisted is properly created.



    ================
    I'm getting the below error

    [TopLink Info]: 2010.11.26 04:08:32.846--ServerSession(2773808)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))
    Exception in thread "main" Local Exception Stack:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseExcep tion
    Internal Exception: java.sql.SQLException: No data found

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    what is :
    <property name="toplink.jdbc.url" value="jdbcdbc:ds_userdsn"/> ???

    Are you able to connect to access db in classic way, with DriverManager ? If so, you have no problem with URL or credentials...

    I guess you successfully created ODBC data source before this?

  3. #3
    The Vicky is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default

    actually it's
    <property name="toplink.jdbc.url" value="jdbc:odbc:ds_userdsn"/>
    :o(colon o) got edited while posting this thread
    ......plz help me if anybody has any idea ......does I need to configure something in MS Access ....... Have I missed to set any property in persistence.xml file???

Similar Threads

  1. Java.net.socket connection :connection closed
    By veeru541 in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2010, 03:14 AM
  2. [URGENT]SHA Encryption System...need urgent helps
    By java_idiot in forum New To Java
    Replies: 6
    Last Post: 05-02-2010, 11:04 AM
  3. Urgent ???
    By programmer_007 in forum Entertainment
    Replies: 0
    Last Post: 04-02-2010, 12:49 PM
  4. Replies: 7
    Last Post: 10-20-2009, 11:34 AM
  5. Very Urgent
    By nehaa in forum AWT / Swing
    Replies: 6
    Last Post: 01-22-2009, 09:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •