There are two ways to use JDBC - using Windows authentication and SQL authentication. SQL authentication is probably the easiest. What you can do is something like:
String userName = "username"; String password = "password"; String url = "jdbc:sqlserver://MYPC\\SQLEXPRESS;databaseName=MYDB"; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn = DriverManager.getConnection(url, userName, password);
after adding sqljdbc4.jar to the build path.
For Windows authentication, you can do something like:
String url = "jdbc:sqlserver://MYPC\\SQLEXPRESS;databaseName=MYDB;integratedSecurity=true"; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn = DriverManager.getConnection(url);
and then add the path to sqljdbc_auth.dll as an argument to the virtual machine (still need sqljdbc4.jar in the build path).
Please look here for a quick walkthrough showing how to connect to SQL Server with Java using jTDS and JDBC so you need more details. Hope this helps!
Thusi Jan 23 '13 at 21:46 2013-01-23 21:46
source share