📄 usersql.java
字号:
import java.sql.*;
////////////开始的入口处在pp2
class UserSql{
Connection con=null;
Statement s=null;
ResultSet rs=null;
String userselname=null,userselsex=null,userselgrade=null,userselbirth=null,userselmajor=null,userselshuse=null,userselcollege=null,usersellike=null,userselxuexing=null,userselintro=null;
public static void main(String args[])throws Exception{
UserSql a=new UserSql();
}
void UserSqlConnect()throws Exception{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Userinfo");
s=con.createStatement();
}
void UserSqlClose()throws Exception{
s.close();
con.close();
}
void Success(){
System.out.println("success!");
}
void Nosuccess(){
System.out.println("no success!");
}
String SelectUserId(String updateid)throws Exception{
this.UserSqlConnect();
String SUNquery="select * from Userinfo where ID=";
SUNquery+=("'"+updateid+"'");
String a="";
try{
rs=s.executeQuery(SUNquery);
while(rs.next()){
a=rs.getString("密码");
}
this.Success();
}catch(Exception e){
this.Nosuccess();
}
this.UserSqlClose();
return a;
}
void UserInsert(String name,String id,String sex,String birthday,String grade,String zhuanye,String password,String shuse,String college,String like,String xuexing,String intro)throws Exception{
this.UserSqlConnect();
String insertquery="insert into Userinfo values(";
insertquery+=("'"+name+"',");
insertquery+=("'"+id+"',");
insertquery+=("'"+sex+"',");
insertquery+=("'"+birthday+"',");
insertquery+=("'"+grade+"',");
insertquery+=("'"+zhuanye+"',");
insertquery+=("'"+password+"',");
insertquery+=("'"+shuse+"',");
insertquery+=("'"+college+"',");
insertquery+=("'"+like+"',");
insertquery+=("'"+xuexing+"',");
insertquery+=("'"+intro+"')");
try{
s.executeUpdate(insertquery);
this.Success();
}catch(Exception e){
this.Nosuccess();
}
this.UserSqlClose();
}
void UserUpdate(String newvalue,String updateid)throws Exception{
this.UserSqlConnect();
String updatequery="update Userinfo set 密码=";
updatequery+=("'"+newvalue+"' ");
updatequery+="where ID=";
updatequery+=("'"+updateid+"'");
try{
s.executeUpdate(updatequery);
this.Success();
}catch(Exception upe){
this.Nosuccess();
}
this.UserSqlClose();
}
void Fuzhi(String userid)throws Exception{
this.UserSqlConnect();
String selectquery="select * from Userinfo where ID=";
selectquery+=("'"+userid+"'");
try{
rs=s.executeQuery(selectquery);
while(rs.next()){
userselname=rs.getString("姓名");
userselsex=rs.getString("性别");
userselgrade=rs.getString("年级");
userselbirth=rs.getString("生日");
userselmajor=rs.getString("专业");
userselshuse=rs.getString("宿舍");
userselcollege=rs.getString("学院");
usersellike=rs.getString("喜欢");
userselxuexing=rs.getString("血型");
userselintro=rs.getString("个人说明");
}
this.Success();
}catch(Exception sen){
this.Nosuccess();
}
this.UserSqlClose();
}
int Check1(String loadid)throws Exception{
this.UserSqlConnect();
String query="select * from Userinfo ";
rs=s.executeQuery(query);
while(rs.next()){
if(loadid.equals(rs.getString("ID"))){
this.UserSqlClose();
return 1;
}
}
this.UserSqlClose();
return 0;
}
String Check2(String loadid)throws Exception{
this.UserSqlConnect();
String query="select * from Userinfo where ID=";
query+=("'"+loadid+"'");
rs=s.executeQuery(query);
while(rs.next()){
String a=rs.getString("密码");
this.UserSqlClose();
return a;
}
this.UserSqlClose();
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -