• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Please help me need urgent help on JPA connection

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.Entit 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="jdbc:odbc: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



================
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


 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you connect TopLink to Access? Access is an odd choice.


 
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..

you might be using a wrong transaction type...

Thanks..
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the Access database is set up as an ODBC data source then the JDBC/ODBC driver can connect to it.

That connection URL looks strange, though. I'd expect it to be in the format jdbc:odbc:DataSourceName. I'd suggest trying that.

(Edited to disable Smilies - does weird things to that URL!)
 
Bhakta Pradhan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all thanks for your quick replies. Hi Mathew the connection URL i have used is what you have mentioned above it got edited automatically while posting this thread.

However I have created a UserDSN named ds_userdsn of type Microsoft Access Driver(*mdb).

Please suggest if i'm doing something wrong here. I would appreciate if anybody can post here sample persistence.xml file required.
 
Marshal
Posts: 71031
291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always indent any code and use the code button, which woul dhave made your code easier to read.
 
Bhakta Pradhan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Campbell for this info...........any idea for my issue ???
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic