📄 loadforum.java
字号:
import java.sql.*;
import java.io.*;
import java.util.*;
public class LoadForum{
private static Connection con;
private static String ua;
private static String un;
private static int ut;
LoadForum(){
//kong gou zao han shu
}
//登录方法
public void forumLoad(){
Scanner shuru=new Scanner(System.in);
try{
con=LoadForum.getConnection();
Statement sta=con.createStatement();
System.out.print("\n会员请登录否则请先注册\n");
System.out.println("* * * * * * * * * * *");
System.out.print("\n请输入昵称:");
String userName = shuru.next();
System.out.print("\n请输入密码:");
String userId=shuru.next();
String strSql = "select account,nickName,userType from usertable where nickName like'" + userName;
strSql = strSql + "' and code='" + userId+"'";
ResultSet rs = sta.executeQuery(strSql);
if (!rs.next()) {
System.out.println("\n无此用户请注册");
System.out.print("\n请输入帐号:");
String userAccount2 = shuru.next();
System.out.print("\n请输入昵称:");
String userName2 = shuru.next();
System.out.print("\n请输入密码:");
String userId2=shuru.next();
String selSql="insert into usertable values('"+userAccount2+"','"+userName2+"','"+userId2+"',0)";
sta.executeUpdate(selSql);
forumLoad();
}
else {
ua=rs.getString(1);
un=rs.getString(2);
ut=rs.getInt(3);
System.out.println("\n***会员信息***");
System.out.print("\n帐号 : ");
System.out.print(rs.getString(1) + "\t");
System.out.print("\n昵称 : ");
System.out.print(rs.getString(2) + "\t");
System.out.print("\n等级 : ");
System.out.print(rs.getInt(3) + "\n");
}
sta.close();
con.close();
}
catch (SQLException ioe) {
System.out.println(ioe);
}
catch (Exception e) {
System.out.println(e);
}
}
public static String userA(){
return ua;
}
public static String userN(){
return un;
}
public static int userT(){
return ut;
}
public static Connection getConnection()
throws SQLException,IOException
{
Properties props=new Properties();
FileInputStream in=new FileInputStream("database3.properties");
props.load(in);
in.close();
String drivers=props.getProperty("jdbc.drivers");
if(drivers!=null) System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return DriverManager.getConnection(url, username, password);
}
public static void forumLoadWay() throws IOException {
LoadForum luntanObj = new LoadForum();
luntanObj.forumLoad();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -