Hello,
I have downloaded "Microsoft SQL Server JDBC Driver 3.0" and tried sample code. I added "sqljdbc.jar" and "sqljdbc4.jar" in Libraries. But getting error,
java.sql.SQLException: No suitable driver found for jdbc:sqlserver:bug_tracking
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Main.main(Main.java:18)
The code is given below :
import java.sql.*;
public class Main {
public static void main(String[] args) {
// Create a variable for the connection string.
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver:bug_tracking","Hakoo-pc","a");
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT * FROM login";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString(4) + " " + rs.getString(6));
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
}