-1
String sql = "Select * from table1 where username=? and password=?";

try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:login");
    System.out.println("you made connection");
    pst = con.prepareStatement(sql);
    pst.setString(1, usernameInput.getText());
    pst.setString(2, passwordField.getText());

    rs = pst.executeQuery();

    if (rs.next()) {
        JOptionPane.showMessageDialog(frame, "Login successful");
    } else {
        JOptionPane.showMessageDialog(frame, "Login unsuccessful");
    }

} catch (Exception e) {
    System.out.println(e);
}

I am trying to connect my database in my application but it doesnt work in Java. it says: no suitable driver found. I searched for answers here but no answer solved my problem. I use SQL Server 2014

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

This may have already been answered, see JDBC ODBC Driver Connection

Two things to note: the JDBC-ODBC bridge was removed in Java 8, and even if you have it, you need to have the ODBC driver configured underneath it.

Here are Microsoft's instructions for creating the ODBC name: https://msdn.microsoft.com/en-us/library/ms403320(v=sql.120).aspx

Community
  • 1
  • 1
argoc
  • 333
  • 1
  • 11