-1

I am trying to connect to mssql server from java but I couldnt figure it out. It throws an exception

ERROR: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MLS_J

here is the code below. What am I doing wrong? How can I fix this?

public static String connection_test(){
    String address  = "jdbc:sqlserver://192.168.1.101:1433;DatabaseName=MLS_J";
    String user = "sa";
    String password = "xxxx";

    try {
            Connection conn = DriverManager.getConnection(address, user, password);
            java.sql.Statement stmt = conn.createStatement();

            return "Bağlantı kapalımı? - " + conn.isClosed();


    } catch (Exception e) {
        return "ERROR: " + e.getMessage();
    }

}
Arif YILMAZ
  • 5,754
  • 26
  • 104
  • 189

2 Answers2

1

You might wanna take a look at this.

Try adding this line to your code:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
Community
  • 1
  • 1
Blub
  • 3,762
  • 1
  • 13
  • 24
1

Follow the steps for adding jar files in build path

  1. Right click on project
  2. click build path-> configure build path
  3. click libraries folder
  4. then click add external jar and give the path of the sqljdbc4.jar.

I would suggest you to use jtds driver.

SpringLearner
  • 13,738
  • 20
  • 78
  • 116