cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to establish connection with SQLServer from Java Application

Former Member
0 Kudos

Dear All,

I am facing the issue of establishing connection with SQL Server from Java project developed in NWDS. I am writing a jaas plug-in, as a part of that I am writing a login module to authenticate a web application through jaas, and I got need of fetching some data from SQL Server which is located in remote host. I am getting error in the line of code

<b>Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")</b>

I also added the 3 jar files (msbase.jar,mssqlserver.jar,and msutil.jar) to my login module project and copied the same files at C:\usr\sap\J2E\JC01\j2ee\cluster\server0\bin\ext\MSSQL.

My MI Landscape is j2ee stack + abap stack +WAS 6.40 with MAXDb as a database.

Could anyone please let me know the solution if you are aware of it.

Thanks and Regards,

Kishore

Accepted Solutions (1)

Accepted Solutions (1)

former_member193399
Active Participant
0 Kudos

You need to add these jar files in the server using visual admin. This will add the driver at the server at the appropriate location. Did you do this?

Also the jar files for SQL Server 2000 and SQL Server 2005 is different. For 200 it is 3 jar files for 2005 it is only one jar file. This is FYI.

Answers (1)

Answers (1)

Former Member
0 Kudos

I solved it by writing the following code

Connection con;

Statement stmt;

DataSource ds;

Context ctx;

ctx = new InitialContext();

if(ctx == null) throw new Exception("Boom - No Context");

ds=(DataSource)ctx.lookup("jdbc/SQLDB");

con = ds.getConnection();

stmt = con.createStatement();

String query = "SELECT * FROM SubjectBIR where Subject_ID='" + user + "'";

ResultSet result = stmt.executeQuery(query);

stmt.close();

con.close();