Rashendra - Rashen
Rashendra - Rashen

Reputation: 139

Connect MS SQL database from Java in ubuntu environment

I am using ubuntu 12.04 and wanted to connect to the MS SQL server database which is hosted in the same network. I was able to connect this using Squirrel , yet unable to connect from a java program. These are the tools I and .jars I am using . Intellij Idea is the tool jar are jtds-1.3.1.jar and sqljdbc4.jar Java version 1.7

I am hoping to develop a web application in the Ubuntu Environment , yet my database will be in Ms Sql windows table. Is this feasible ? Please intruct me step by step , and sample code to connect ms sql database which s hosted ina wondows environment

Rashen

Upvotes: 0

Views: 5095

Answers (3)

MirecXP
MirecXP

Reputation: 443

Don't care about the OS. Have you tried the recommended way to connect using the MS SQL JDBC Driver?

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

String dbHostName = "windowsHostName";
String dbName = "myDb";
String dbUserName = "myUserName";
String dbPassword = "topSecret";

String connectionUrl = "jdbc:sqlserver://" + dbHostName + ":1433;" +
   "databaseName=" + dbName + ";user=" + dbUserName + ";password=" + dbPasword + ";";
Connection con = DriverManager.getConnection(connectionUrl);

Upvotes: 1

chouk
chouk

Reputation: 289

It does not change anything that your DB is hosted on Linux / Windows, as long as you can access it through your network.

There is a post where you can see how to connect to your DB from Java using jTDS: Connect to SQL Server 2012 using jTDs

If it does not solve your problem, can you give us your exact error message?

Upvotes: 0

J-16 SDiZ
J-16 SDiZ

Reputation: 26910

Both microsoft's driver and jTDS works on linux.

Their web site have example jdbc urls.

Upvotes: 1

Related Questions