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: 
```
package com.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DatabaseUtil1 {

    public static final String DRIVER="oracle.jdbc.driver.OracleDriver";
    public static final String URL="jdbc:oracle:thin:@DIPAK-PC:1521:xe";
    public static final String USERNAME="system";
    public static final String PASSWORD="password";

    public static Connection getConnection() throws ClassNotFoundException, SQLException
    {
        Connection con= null;

        Class.forName(DRIVER);
        con=DriverManager.getConnection(URL,USERNAME,PASSWORD);

        System.out.println(con);
        return con; 
    }
    public static void closePreparedStatement(PreparedStatement pst) throws SQLException
    {
        if(pst!=null)
        {
            pst.close();
        }

    }
    public static void closeConnection(Connection con) throws SQLException
    {
        if(con!=null)
        {
            con.close();
        }

    }

}

```
Use the below code. This will work

```
import java.sql.*;  
class MysqlCon{  
public static void main(String args[]){  
try{  
Class.forName("com.mysql.jdbc.Driver");  
Connection con=DriverManager.getConnection(  
"jdbc:mysql://localhost:3306/sonoo","root","root");  
//here is database name, root is username and password  
Statement stmt=con.createStatement();  
ResultSet rs=stmt.executeQuery("select * from emp");  
while(rs.next())  
System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
con.close();  
}catch(Exception e){ System.out.println(e);}  
}  
}  

```