java中如何用数据库做一个登陆界面(其中有老师和学生、辅导员登陆)
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏20(财富值+成长值)
展开全部
使用JDBC连接SQL数据库就可以了
至于如何使用,自行百度吧,
/* 连接数据库,验证用户 */
try {
Class.forName(MainFrame.DB_NAME);
connect = DriverManager.getConnection(MainFrame.DB_URL, "sa",
"server");
list = connect.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
} catch (ClassNotFoundException | SQLException e1) {
JOptionPane.showMessageDialog(null, e1.toString());
}
try {
// ///////////* 验证登录用户*////////////////////////////////
result = list
.executeQuery("select * from UserInfo where UserID='"
+ text_UserName.getText().toString().trim()
+ "' and Password='"
+ new String(text_Password.getPassword()) + "'");
while (result.next()) {
flag = true;
choice = 1;
MainFrame.login_name = text_UserName.getText().toString()
.trim();
break;
}
if (!flag) {
result = list
.executeQuery("select * from ReadersInfo where ReaderID='"
+ text_UserName.getText().toString().trim()
+ "' and Password='"
+ new String(text_Password.getPassword())
+ "'");
while (result.next()) {
flag = true;
choice = 2;
MainFrame.login_name = text_UserName.getText()
.toString().trim();
break;
}
}
参考一下
至于如何使用,自行百度吧,
/* 连接数据库,验证用户 */
try {
Class.forName(MainFrame.DB_NAME);
connect = DriverManager.getConnection(MainFrame.DB_URL, "sa",
"server");
list = connect.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
} catch (ClassNotFoundException | SQLException e1) {
JOptionPane.showMessageDialog(null, e1.toString());
}
try {
// ///////////* 验证登录用户*////////////////////////////////
result = list
.executeQuery("select * from UserInfo where UserID='"
+ text_UserName.getText().toString().trim()
+ "' and Password='"
+ new String(text_Password.getPassword()) + "'");
while (result.next()) {
flag = true;
choice = 1;
MainFrame.login_name = text_UserName.getText().toString()
.trim();
break;
}
if (!flag) {
result = list
.executeQuery("select * from ReadersInfo where ReaderID='"
+ text_UserName.getText().toString().trim()
+ "' and Password='"
+ new String(text_Password.getPassword())
+ "'");
while (result.next()) {
flag = true;
choice = 2;
MainFrame.login_name = text_UserName.getText()
.toString().trim();
break;
}
}
参考一下
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询