import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /** * @author mwood */ public class TestSQLServer2005ExpressConnexion { public static void main(String[] args) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (Exception e) { System.err.println("Failed to load JDBC implementation driver"); return; } try { // This works // Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS", "sa", "p@55w0rd"); // And so does this // Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS;user=sa;password=p@55w0rd"); // And so does this Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=p@55w0rd;instanceName=SQLEXPRESS"); // And if you are not using the default database // Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=p@55w0rd;instanceName=SQLEXPRESS;databaseName=myotherdb"); // But there seems to be no way of specifiying port! so you are stuck with default 1433! Statement select = con.createStatement(); ResultSet result = select.executeQuery("select * from dbo.sysobjects"); // this table should exist on any installation while (result.next()) { System.out.println("result"); } select.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }