你好,我想知道你是否可以帮助我。我的应用程序上有一个登录表单或框架。它有用户名和密码文本字段,我的应用程序连接到访问数据库。我希望用户在可以在应用程序上执行其他操作之前登录。在visual basic中是小菜一碟,但在java中是一块石头,这是我拥有的代码
import java.sql.*;
public class Login1 extends JavaApplication1
{
private static Connection conn;
static Statement state;
public static void login()
{
String url = "jdbc:odbc:Java_Testing";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(url);
System.out.println("The driver was loaded successfully");
}
catch(ClassNotFoundException error)
{
System.out.println("Unable to load the driver" + error);
}
catch(SQLException error)
{
System.out.println("Could not connect to the database" + error);
}
try
{
String query1 = "SELECT Username , User_Password From Users Where Username = ('"+ JavaApplication1.txtUsername.getText() + "' AND User_Password ='" + JavaApplication1.txtPassword.getText() + "')";
state = conn.createStatement();
ResultSet results = state.executeQuery(query1);
System.out.println("Congradulations you have succefully loged in");
}
catch(Exception error)
{
System.out.print("Enable to login the user: " + error);
}
}
}
JavaApplication1
只是另一个进行所有事件处理并具有 awt 控件的类。
当我运行此代码时,这是我得到的错误
Unenable to to login the user: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
如果您有答案,请分享并再次查看第二个尝试块,我知道问题出在哪里。
提前致谢。