If you are configuring a named instance SQL Server Express 2005 to work with JDBC, here are some pointers.
If you are having a little trouble with your connection string and named instances of SQL Server. My connection string looks like this:
private static final String _DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; private static final String _CON_STRING = "jdbc:sqlserver://localhost\\SQLExpress"; + "PortNumber=1433;databaseName=TEST;username=**********;password=**********;";
At this point I no longer had the connection refused error or any other errors for that matter from the following code:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.*; ... try { Class.forName(_DRIVER).newInstance(); Connection con = DriverManager.getConnection(_CON_STRING); Statement s = con.createStatement(); ResultSet rs = s.executeQuery("SELECT * FROM dbo.tester"); ResultSetMetaData rsMeta = rs.getMetaData(); System.out.println("Column Count: " + rsMeta.getColumnCount()); int ccnt = rsMeta.getColumnCount(); for (int cols=1; cols<=ccnt; cols++) { System.out.print(rsMeta.getColumnName(cols) + " "); } System.out.println(" "); while (rs.next()) { for (int i=1; i <= ccnt; i++) { System.out.print(rs.getString(i) + " "); } System.out.println(" "); } rs.close(); con.close(); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println(e.getStackTrace()); }