NinethSense oWnZ mE!: Praveen’s drawing book

Choose a Topic:

Wed
20
Feb '08

Connect to Microsoft SQL Server from Java

Here is the way you can connect to your Microsoft SQL Server 2005 from your java application via JDBC.

First you need to download the Microsoft SQL Server 2005 JDBC Driver.
You will get sqljdbc.jar which is all you needed. As a java programmer, you know how to use this, right? ;)

You will get a user manual along with this download. Follow the instructions. Or here is a sample code for your quick reference:

 
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
Connection conn = DriverManager.getConnection(“jdbc:sqlserver://servername\SQLEXPRESSinstance;database=yourdatabase;user=your username”);
Statement stmt = conn.createStatement();
		
String qry = “SELECT * FROM yourtable”;
ResultSet rs = stmt.executeQuery(qry);
 
while (rs.next()) {
    // code;
}
The CodeProject Microsoft Developer Network Official ASP.NET Forums Microsoft .NET Framework Community Microsoft Most Valuable Professional Kidoos forums Microsoft Visual Studio Developer Home Professional Information Technology Solutions Microsoft Research Home Kerala Microsoft Users Group Community Website