简体   繁体   中英

Access SQL Server 2008 R2 database from netbeans 8

I am completely new to java, and I want to make a connection to a remote SQL server 2008 R2 database (like 192.168.17.11) and load data from it. Please suggest alternative ways if you know any.

First you must have JDBC driver for MS SQL, you have two jars (jtds-1.2.5.jar or sqljdbc4-2.0.jar), which added to your classpath

Second you need to create your connection as below:

String password="pass";
String driver= "net.sourceforge.jtds.jdbc.Driver"; // For sqljdbc4, use: com.microsoft.sqlserver.jdbc.SQLServerDriver
String username="user";
String URL="jdbc:jtds:sqlserver://serverIP:port/dbname"; // For sqljdbc4, use: jdbc:sqlserver://serverIP:port;databaseName=dbname
Class.forName(driver);
Connection conn = DriverManager.getConnection(URL, username, password);

// Use your connection here
// Don't forget to close the connection

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