title: The connection to the host server failed. Java
body: <p>I'm trying to run a query but I keep getting this error:</p>
  
  <p>The connection to the host server=localhost, named instance sqlexpress failed. Error: "java.net.UnknownHostException: server=localhost". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434.  For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.</p>
  
  <p>Any ideas? Here's my code.</p>
  
  <pre><code>public static void main(String[] args) {
          try {
              try {
                  // TODO code application logic here
                  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  
             // Connection dbConnection = DriverManager.getConnection("jdbc:jtds:sqlserver://127.0.0.1:1433/myDatabase; instance = SQLEXPRESS","sa","password");
              String Connectionurl="jdbc:sqlserver://server=Owner-PC\\SQLEXPRESS; DatabaseName=myDatabase;";
              Connection dbConnection = DriverManager.getConnection(Connectionurl,"sa","password");
               Statement myStmt  = dbConnection.createStatement();
  
                  String query = "INSERT INTO People(ID, Name, Surname, Age, Contact, Location, Course) VALUES"
                          + " (1007, 'Elroy', 'Smith', 33, 21366688, 'Somewhere', 'somecourse')";
  
                  myStmt.executeUpdate(query);
  
  
                  myStmt.executeQuery(query);
  
                  } catch (ClassNotFoundException ex) {
                  Logger.getLogger(JavaApplication2.class.getName()).log(Level.SEVERE, null, ex);
              }
          } catch (SQLException ex) {
               Logger.getLogger(JavaApplication2.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  </code></pre>