Skip to content

Instantly share code, notes, and snippets.

@Haosvit
Last active April 22, 2016 08:48
Show Gist options
  • Save Haosvit/ef679906ef3075389d8da5ecdcc707f7 to your computer and use it in GitHub Desktop.
Save Haosvit/ef679906ef3075389d8da5ecdcc707f7 to your computer and use it in GitHub Desktop.
1. String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
2. String connectionURL = "jdbc:sqlserver://" + hostname + ":1433;"
+ ";instance=." + ";databaseName=" + databaseName + ";user=" + user + ";password=" + password + ";";
3. // register drive sql jdbc
Class.forName(driverName);
4. // create connection;
Connection conn = DriverManager.getConnection(connectionURL);
// create statement for execute queries
Statement st = conn.createStatement();
5. Check port 1433, make sure it was opened
in cmd, type: netstat -an -P TCP
looking for port 1433 in the list, if it is not there, do the follow steps
5.1 Go to Sql server configuration manager, enable TCP/IP at Protocol for <Your SQL server instance>
5.2 Restart sever instance
5.3 Check again in cmd (netstat -an -P TCP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment