title: Connecting Java with SQL express
body: <p>I've designed a database management system using Java and MySQL. I used <strong>WAMP</strong> as the server. Everything was perfect with that..until now..</p>
  
  <p>Now, I have to go for <strong>SQL Express</strong> instead of <strong>WAMP</strong>. I know nothing about SQL Express. I've installed it under defaults. </p>
  
  <p>However, now I can connect to the database in <strong>Microsoft SQL Server Management Studio</strong> with following selections,
  (<code>LORDXAX-PC</code> is my computer's name)</p>
  
  <p><img src="https://i.stack.imgur.com/SRCDQ.png" alt="enter image description here"></p>
  
  <p>But I need to connect the database with my Java program. <em>(I've used <strong>JDBC</strong> successfully before, with WAMP)</em></p>
  
  <p>Need help to make this a success?? I've tried searching found certain things, but it gives errors. Can someone provide me with <em>clean</em> instructions..</p>
  
  <p>Any help is appreciated. Thanks!</p>
  
  <hr>
  
  <h2>EDIT (2)</h2>
  
  <p>This is a complete code demonstrating the issue..</p>
  
  <pre><code>package ExpressTest;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  
  public class MAIN {
  
      public static void main(String[] args) {
          new MAIN().start();
      }
  
      private void start() {
          System.out.println("START");
          String query = "SELECT * FROM logindata";
          getData(query);
          System.out.println("END");
      }
  
      public ResultSet getData(String query) {
          Connection CON = null;
          try {
              Class.forName("net.sourceforge.jtds.jdbc.Driver");
              CON = DriverManager.getConnection(URL, USER, PASS);
              RESULT = CON.createStatement().executeQuery(query);
          } catch (Exception ex) {
              ex.printStackTrace();
          }
          return RESULT;
      }
      private String URL = "jdbc:jtds:sqlserver://localhost/brandix;instance=sqlexpress";
      private String USER = "";
      private String PASS = "";
      private static ResultSet RESULT;
  }
  </code></pre>
  
  <p>This is the complete <code>NetBeans</code> output.</p>
  
  <pre><code>run:
  START
  java.sql.SQLException: Network error IOException: Connection refused: connect
      at net.sourceforge.jtds.jdbc.ConnectionJDBC2.&lt;init&gt;(ConnectionJDBC2.java:417)
      at net.sourceforge.jtds.jdbc.ConnectionJDBC3.&lt;init&gt;(ConnectionJDBC3.java:50)
      at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:185)
      at java.sql.DriverManager.getConnection(DriverManager.java:582)
      at java.sql.DriverManager.getConnection(DriverManager.java:185)
      at ExpressTest.MAIN.getData(MAIN.java:24)
      at ExpressTest.MAIN.start(MAIN.java:16)
      at ExpressTest.MAIN.main(MAIN.java:10)
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
      at java.net.Socket.connect(Socket.java:519)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  END
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:311)
      at net.sourceforge.jtds.jdbc.SharedSocket.&lt;init&gt;(SharedSocket.java:261)
      at net.sourceforge.jtds.jdbc.ConnectionJDBC2.&lt;init&gt;(ConnectionJDBC2.java:318)
      ... 7 more
  BUILD SUCCESSFUL (total time: 7 seconds)
  </code></pre>