Question: I am newbie to java db coding...

This is my java code

```
Connection conn = null;
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection("jdbc:mysql://localhost/EMP",USER,PASS);
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;

```

This is the exception I am getting : 

```
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/tiles].[default]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet default threw exception: java.net.ConnectException: Connection refused: connect

```

I am mySQL server also running and contains simple table named EMP. I am not interpreting the get connection URL comppletely. Can anyone explain it briefly?

Thanks.

Answer: 
You are using the wrong driver for the database. Every database (MySQL, PostgreSQL, SQL Server, Oracle etc.) has a different driver which is what connects between JDBC and the particular database's communication protocol.

You need the Microsoft SQL Server driver. You can download and install it from here if you don't already have it: [Microsoft down page for JDBC 4.0 driver](http://www.microsoft.com/en-us/download/details.aspx?id=11774).

And here are the [instructions](http://technet.microsoft.com/en-us/library/ms378526%28v=sql.110%29.aspx) on how to add the jar to your classpath, and what URL to use. Note that in JDBC 4.0 and above, the `forName` is not necessary anymore.
Download the Microsoft JDBC driver and use `Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver);`

If the problem still persists enable TCP/IP network protocol, which is disabled by default, and set the TCP/IP port to 1433 which is the default port number.