javasql-serverjpatoplink

Making a ms sql connection in persistence.xml in JPA


We need to make a connection to ms sql server from java persistence unit 1.0. I hace following code for oracle database.

<properties>
        <property name="toplink.jdbc.url" value="jdbc:oracle:thin:@IP:PORT"/>
        <property name="toplink.jdbc.user" value="####"/>
        <property name="toplink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="toplink.jdbc.password" value="####"/>
        <property name="toplink.ddl-generation" value="create-tables"/>
        <property name="toplink.jdbc.read-connections.max" value="1"/>
        <property name="toplink.jdbc.read-connections.min" value="1"/>
        <property name="toplink.jdbc.write-connections.max" value="1"/>
        <property name="toplink.jdbc.write-connections.min" value="1"/>
        <property name="toplink.logging.level" value="SEVERE" />
    </properties>

I need the changes that I have to make in the previous code for making a connection to MS Sql Server.


Solution

  • Finally I got the solution..... Steps to make connection to ms sql from JPA persistence.xml are:

    1. Download the jar files from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=21599
    2. I chose sql server 2005 so I used sqljdbc4 jar file from the above link.
    3. Change driver name to com.microsoft.sqlserver.jdbc.SQLServerDriver in above given xml file.
    4. Provide necessary username and password at corresponding position in xml file.
    5. In connection url, write jdbc:sqlserver://localhost:port;databaseName=<Database>