Creating connection to databse using java service

Hello,

I want to create a connection to a database from a Java service rather than an adapter service and i am doing this for my practice purpose (creating a “how to connect to databse using Java service” document). Any pointers or references to a java code is appreciated.

I am connecting to MSSQL server 2005 from IS 7.1.2. The inputs that i will be providing are database URL, Driver class and username/password.

Note:

This is not regarding using an existing connection, it has to create a new connection in the code.

Akki,

What you got to do it simply embed the java connectivity code in a java service.
Here is the sample code:

import java.sql.*;
try
{
Class.forName( “com.microsoft.jdbc.sqlserver.SQLServerDriver”);

                    Connection conn = DriverManager.getConnection(          "jdbc:microsoft:sqlserver://server:port;User='';Password=");                          

                    System.out.println("connected");
                    
            }
            catch (Exception e)
            {
                    e.printStackTrace();
                    return null;
            }

just make sure you have the jars at the right place.

  • HS

I would strongly encourage not doing this and instead use the facilities provided by the JDBC adapter. If you must access a DB while running a Java service, use the IS Java API to invoke a proper JDBC service.

Rob,

I understand the concern and it was just a curious how to thing.

Harsh,

Thanks for the pointer.

Cheers,
Akshith