学生学籍管理java acess.docx
《学生学籍管理java acess.docx》由会员分享,可在线阅读,更多相关《学生学籍管理java acess.docx(40页珍藏版)》请在冰点文库上搜索。
学生学籍管理javaacess
河南理工数据库课程设计学生学籍管理java和acess源代码:
附源程序
importjava.util.Scanner;
importjava.sql.*;
publicclassStudent
{
staticbooleanflag;//标记是否为管理员
staticinti=0;//限制密码输入次数
staticStringpresent_name;//记录当前用户
publicstaticvoidlog_in(Stringname,Stringpwd)throwsException//用户登录验证
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
ResultSetrs=null;
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
rs=stmt.executeQuery("Select*Fromuserswhereusername='"+name+"'andpassword='"+pwd+"'");
if(rs.next())
{
System.out.println("登录成功!
");
}
else
{//设置三秒后关闭程序
i++;
if(i==3)
{
intj;
System.out.println("登录错误次数已经三次。
系统将在三秒后关闭!
");
for(j=0;j<3;j++)
{
Thread.sleep(1000);
System.out.println((3-j));
}
if(j==3)
{
System.exit(0);
}
}
else
{
System.out.println("您的用户名或密码不正确!
请重新登录!
");
System.out.println("您还有"+(3-i)+"次机会");
Scannerreader=newScanner(System.in);
System.out.println("请输入您的用户名:
");
Stringusername=reader.nextLine();
System.out.println("请输入您的密码:
");
Stringpassword=reader.nextLine();
log_in(username,password);
}
}
if(name.equals("Administrator"))
{
flag=true;//设个管理员的标志位
}
else
{
flag=false;
}
}
publicstaticvoidstudent_watch()throwsException//当前学生信息
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
ResultSetrs=null;
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
rs=stmt.executeQuery("Select*Fromstudent");
while(rs.next())
{
System.out.print(rs.getString("sno")+"");
System.out.print(rs.getString("sname")+"");
System.out.print(rs.getString("ssex")+"");
System.out.print(rs.getInt("sclass")+"");
System.out.print(rs.getInt("sage")+"");
System.out.println(rs.getString("sdept")+"");
}
}
publicstaticvoidchange_secret()throwsException//修改密码_通用(出现点问题。
密码修改不了!
?
?
?
)
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
/*ResultSetrs=null;*/
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
System.out.println("您想把密码改为:
");
Scannerreader=newScanner(System.in);
Stringpwd1=reader.nextLine();
System.out.println("请重复新密码:
");
Stringpwd2=reader.nextLine();
if(pwd1.equals(pwd2))
{
Stringsql="updateuserssetpassword='"+pwd1+"'whereusername='"+present_name+"'";
try
{
stmt.executeQuery(sql);
}
catch(Exceptione)
{
;
}
System.out.println("密码修改成功!
下次登录请用新的密码!
");
/*Stringsql1="select*fromuserswhereusername='"+present_name+"'";
rs=stmt.executeQuery(sql1);
System.out.println(rs.getString("password"));
if(pwd1.equals(rs.getString("password")))
{
System.out.println("密码修改成功!
下次登录请用新的密码!
");
}
*/
}
else
{
System.out.println("两次密码输入不相同。
无法完成修改!
");
}
}
publicstaticvoidadmin_watch_users()throwsException//查看当前用户信息_管理员
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
ResultSetrs=null;
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
rs=stmt.executeQuery("Select*Fromusers");
while(rs.next())
{
System.out.println(rs.getString("username")+"");
}
}
publicstaticvoidadmin_create_user()throwsException//创建用户_管理员
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
ResultSetrs=null;
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
booleana=true;
while(a)
{
Scannerscr=newScanner(System.in);
System.out.println("请输入用户名:
");
Stringusername=scr.nextLine();
Stringstrsql=("select*fromuserswhereusername='"+username+"'");
rs=stmt.executeQuery(strsql);
if(rs.next())
{
a=false;
System.out.println("输入有误!
此用户名已经存在!
");
break;
}
System.out.println("请输入密码:
");
Scannerreader=newScanner(System.in);
Stringpwd1=reader.nextLine();
System.out.println("请重复密码:
");
Stringpwd2=reader.nextLine();
if(pwd1.equals(pwd2))
{
Stringsql="insertintousersvalues(?
?
)";
PreparedStatementpstmt=con.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,pwd1);
intintTemp=pstmt.executeUpdate();
if(intTemp!
=0)
{
a=false;
System.out.println("用户创建成功!
");
}
}
else
{
System.out.println("两次密码输入不相同。
无法完成创建!
");
}
}
}
publicstaticvoidadmin_delete_user()throwsException//删除用户_管理员
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
System.out.println("请输入所要删除用户名:
");
Scannerreader=newScanner(System.in);
Stringname_d=reader.nextLine();
Stringsql="deletefromusersWHEREusername='"+name_d+"'";
stmt.executeUpdate(sql);
System.out.println("删除成功!
");
}
publicstaticvoidadmin_student_insert()throwsException//插入学生信息
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
ResultSetrs=null;
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
booleana=true;
while(a)
{
Scannerscr=newScanner(System.in);
System.out.println("请输入学生的学号:
");
Stringsno=scr.nextLine();
Stringstrsql=("select*fromstudentwheresno='"+sno+"'");
rs=stmt.executeQuery(strsql);
if(rs.next())
{
a=false;
System.out.println("输入有误!
此学号已经存在!
");
break;
}
System.out.println("请输入学生的姓名:
");
Stringsname=scr.nextLine();
System.out.println("请输入学生的性别:
");
Stringssex=scr.nextLine();
System.out.println("请输入学生的班级:
");
intsclass=Integer.parseInt(scr.nextLine());
System.out.println("请输入学生的年龄:
");
intsage=Integer.parseInt(scr.nextLine());
System.out.println("请输入学生的专业:
");
Stringsdept=scr.nextLine();
System.out.println("您所要插入的信息为:
"+sno+""+sname+""+ssex+""+sclass+""+sage+""+sdept);
System.out.println("确认填加信息吗?
(y/n):
");
Stringchioce=scr.nextLine();
if(chioce.equals("y"))
{
Stringsql="insertintostudentvalues(?
?
?
?
?
?
)";
PreparedStatementpstmt=con.prepareStatement(sql);
pstmt.setString(1,sno);
pstmt.setString(2,sname);
pstmt.setString(3,ssex);
pstmt.setInt(4,sclass);
pstmt.setInt(5,sage);
pstmt.setString(6,sdept);
intintTemp=pstmt.executeUpdate();
if(intTemp!
=0)
{
System.out.println("插入成功!
");
a=false;
}
}
else
{
System.out.println("插入已经取消!
");
a=false;
}
}
}
publicstaticvoidadmin_change()throwsException//修改学生信息
{
StringDBDrive="sun.jdbc.odbc.JdbcOdbcDriver";
StringconnectionStr="jdbc:
odbc:
conn";
Connectioncon=null;
Statementstmt=null;
ResultSetrs=null;
Class.forName(DBDrive);
con=DriverManager.getConnection(connectionStr,"sa","sa");
stmt=con.createStatement();
Scannerreader=newScanner(System.in);
System.out.println("请输入您所要修改的学生的学号:
");
Stringsno_before=reader.nextLine();
Stringsql="select*fromstudentwheresno='"+sno_before+"'";
rs=stmt.executeQuery(sql);
booleana=true;
if(rs.next())
{
while(a)
{
System.out.println("您可以有以下操作:
");
System.out.println("1、修改学号");
System.out.println("2、修改姓名");
System.out.println("3、修改性别");
System.out.println("4、修改班级");
System.out.println("5、修改年龄");
System.out.println("6、修改专业");
System.out.println("0、返回上一步");
System.out.println("请输入您的选择:
");
intchioce_change=Integer.parseInt(reader.nextLine());
Stringstrsql=null;
switch(chioce_change)
{
case1:
System.out.println("请输入您所要更改为:
");
Stringsno_after=reader.nextLine();
strsql="updatestudentsetsno='"+sno_after+"'wheresno='"+sno_before+"'";
//此处不知错在何处。
如何不使用异常处理。
try
{
stmt.executeQuery(strsql);
}
catch(Exceptione)
{
;
}
System.out.println("修改成功!
");
break;
case2:
System.out.println("您想把名字更改为:
");
Stringsname=reader.nextLine();
strsql="updatestudentsetsname='"+sname+"'wheresno='"+sno_before+"'";
try
{
stmt.executeQuery(strsql);
}
catch(Exceptione)
{
;
}
System.out.println("修改成功!
");
break;
case3:
System.out.println("您想把性别更改为:
");
Stringssex=reader.nextLine();
strsql="updatestudentsetssex='"+ssex+"'wheresno='"+sno_before+"'";
try
{
stmt.executeQuery(strsql);
}
catch(Exceptione)
{
;
}
System.out.println("修改成功!
");
break;
case4:
System.out.println("您想把年龄更改为:
");
intsage=Integer.parseInt(reader.nextLine());
strsql="updatestude