Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need urgent help to connect to Database

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need urgent help to connect to Database

    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


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Need urgent help to connect to Database

    What is UserDetails? What line is the exception thrown on? What is the database scema?

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need urgent help to connect to Database

    In MS Access it's not asking for user credential ...........also I've not created any schema ......

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Need urgent help to connect to Database

    Quote Originally Posted by The Vicky View Post
    In MS Access it's not asking for user credential ...........also I've not created any schema ......
    You first must create the schema which corresponds to the entity bean mapping, otherwise there is no place to enter the data.

Similar Threads

  1. Replies: 6
    Last Post: August 18th, 2010, 06:41 PM
  2. How to connect keyboard through COM?
    By yogesh01 in forum Java Theory & Questions
    Replies: 0
    Last Post: July 6th, 2010, 06:00 AM
  3. Connection refused: connect
    By kirts in forum Java Networking
    Replies: 0
    Last Post: April 16th, 2010, 12:53 PM
  4. Java Swing Tables ( JTable Models ) to connect to Database
    By javaprogrammer in forum JDBC & Databases
    Replies: 0
    Last Post: January 26th, 2010, 04:13 PM
  5. Replies: 0
    Last Post: January 26th, 2010, 04:10 PM