0

I need to connect to a Microsoft SQL server using Java.

I downloaded the driver, an no matter what I did elipse and netbeans could not find the driver.

When I got frustrated I downloaded also MySql driver, and again I get the same exception.

I added the drivers path in the environmental variables and also included the jar files in my project library.

Here is a picture of my project:

pic http://i56.tinypic.com/1ekple.jpg

What am I doing Wrong?

Thank you very much, Idan.

4
  • "When I got frustrated i downloaded also MySql driver" What were you thinking?? MS SQL != MySQL. Commented Jun 16, 2011 at 16:46
  • Trying to use com.mysql.jdbc.Driver for an msql: connection will definitely not work. What's the error message with the MS SQL JDBC driver? Commented Jun 16, 2011 at 16:46
  • I installed a mysql server to try on, i didnt try to connect to mysql server using MS driver. this is what happens when i use the MS driver: i54.tinypic.com/2prcx7k.jpg Commented Jun 16, 2011 at 16:55
  • read the jTDS FAQ. The URL format for jTDS is different from the one used by MS SQL JDBC driver. Commented Jun 16, 2011 at 17:06

3 Answers 3

1

A few problems:

  1. Your JDBC url should be jdbc:mssql instead of jdbc:msql
  2. The port for SQL Server is usually 1433, not 8888 but can be configured.
  3. The driver specified is for MySQL and won't work.

Start to correct by downloaded a MS SQL JDBC driver, there are 2 popular varients:

Open source: http://jtds.sourceforge.net/

Microsoft: http://msdn.microsoft.com/en-us/sqlserver/aa937724

I've used both and haven't had much problems in either case.

EDIT

The only example I have currently is using the microsoft driver, here it is:

DRIVER: com.microsoft.sqlserver.jdbc.SQLServerDriver

URL: jdbc:sqlserver://localhost:1433;database=<MyDB>
Sign up to request clarification or add additional context in comments.

2 Comments

check that the driver you are using is on your classpath, and that your sql server is running on port 8888. like previously mentioned, this is not the normal port.
Edited question to include sample using microsoft driver.
0

There is a typo in the url in order to connect to mysql.

It should be jdbc:mysql://127.0.0.1:8888

Also I would double check if your mysql server is actually running on port 8888 since normally a mysql answers on 3306.

Also there are multiple JDBC drivers for Microsofts' SQL server, which have different url. For the microsoft driver the url looks like jdbc:microsoft:sqlserver://localhost:1433

Check the documentation of the driver for an example url to start from.

2 Comments

mySql server is easyphp server and it is 8888 port and i can connect to it through cmd
With easyphp the webserver listens on port 8888. Mysql listens also on port 3306 by default when installing easyphp.
0

Try with jTDS. It is an open source JDBC 3.0 driver for Microsoft SQL Server (6.5, 7, 2000 and 2005). Place jar file into your application classpath. java.sql package along with above driver helps connecting to database.

import java.sql.*;

public class testConnection
{
    public static void main(String[] args) 
    {
        DB db = new DB();
        db.dbConnect(
     "jdbc:jtds:sqlserver://localhost:1433/tempdb","sa","");
    }
}

class DB
{
    public DB() {}

    public voidn dbConnect(String db_connect_string, 
  String db_userid, String db_password)
    {
        try
        {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            Connection conn = DriverManager.getConnection(
    db_connect_string, db_userid, db_password);
            System.out.println("connected");

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.