Question: I would like to know how to connect to database in which is hosted in Xampp MySQL.

This is what I have so far in my java code to connect but I'm unsure what I'm doing. 

```
public static void main(String[] args) {
    try {
        Connection con = DriverManager.getConnection( host, username, password );
        String host = "jdbc:derby://localhost:1527/Employees";
        String uName = "root";
        String uPass= "password";
    }
    catch ( SQLException err ) {
    System.out.println( err.getMessage( ) );
    }

}

```

1. What would the host URL be?
2. Do i need a JDBC Jar file to connect to the DB?

I have setup a database and table via phpMyAdmin already. Just don't know how to proceed.

I am using **Netbeans** to write my Java code to connect to a local database which was created via **Xampp PHPMyAdmin**.

In the end, I want to create a database connection in Java and call out tables within the IDE. Would appreciate some help.

Answer: 
This is a code (Java 7 style, try-with-resources, more laconic style) to connect and retrieve data from your DB. 

```
 public static final String SELECT_QUERY = "SELECT * FROM your_table_name";
 public static void main(String[] args) {
    String host = "jdbc:derby://localhost:1527/Employees";
    String uName = "root";
    String uPass = "password";

    try (Connection conn = DriverManager.getConnection(host, uName, uPass);
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery(SELECT_QUERY)) {

        while (rs.next()) {
            //read your lines one ofter one
            int id = rs.getInt("id");
            String somePropertyValue = rs.getInt("some_column_name");
            // etc. 
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

```

Also, add JDBC driver (\*.jar file) in your classpath if you are running from command line, or add this jar to your project, if you are working in IDE (Eclipse, IDEA etc. It is a little bit different for each one).

BTW, How your code compiled if variable declaration is after they using? That code can not be compiled even.
Maybe you should define your strings before use them.

The host URL seems good. 

You have to install the driver in your server, or to put it in the `/lib` folder of your project. You fill find it in `%DERBY_HOME%/lib` folder, named `derby.jar`, assuming `%DERBY_HOME%` is the directory installation of Derby.