Making a ms sql connection in persistence.xml in JPA

10,365

Solution 1

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>

Solution 2

Microsoft SQL Server connection can be done in few ways. To use windows authentication, you need to place a dll file in your System 32 directory. After that, you can replace the

connection URL, and user credentials as required. You may need to configure your SQL server by SQL Server Surface Configuration Manager to allow remote connections and connections through TCP IP.

After that you may try to connect through a plain java class. And after that connect using a persistence unit (in EJB?).

When you download the SQL Server - JDBC Connector ZIP file, you can find a HTML Documentation, which you must read (it will take 20 minutes). It was a 2 day struggle for me to connect to SQL Server from JDBC.

Share:
10,365
Sushant Jain
Author by

Sushant Jain

Updated on August 07, 2022

Comments

  • Sushant Jain
    Sushant Jain over 1 year

    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.