简体   繁体   中英

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

Both microsoft's driver and jTDS works on linux.

Their web site have example jdbc urls.

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM