📄 right.java
字号:
import java.sql.*;
import java.io.*;
import java.util.*;
public class Right{
Right(){
// kong gou zao
}
//修改帖子
public static void modifyRecord() {
try {
Scanner shuru=new Scanner(System.in);
System.out.print("\n 请输入要修改"
+ "帖子号: ");
int forumnumber = Integer.parseInt(shuru.next());
try{
Connection conn=LoadForum.getConnection();
Statement stat=conn.createStatement();
String printorder=new String("select nickName,content,dataTime from messagetable where forumnumber="+forumnumber);
ResultSet ztr=stat.executeQuery(printorder);
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * ");
while(ztr.next()){
System.out.println(" "+ztr.getString(1)+"\t"+ztr.getString(2)+"\t"+ztr.getString(3));
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * ");
}
stat.close();
conn.close();
}
catch(Exception e){
System.out.print(e);
}
System.out.print("\n请输入要修改后的内容: ");
String course = shuru.next();
Connection con=LoadForum.getConnection();
Statement sta=con.createStatement();
String strSql="Update messagetable set content ='" + course
+"'where messagetable.forumNumber="+forumnumber;
sta.executeUpdate(strSql);
System.out.print("\n帖子已成功修改 !");
System.out.println();
sta.close();
con.close();
}
catch (SQLException ioe) {
System.out.println(ioe);
}
catch (Exception e) {
System.out.println(e);
}
}
//删除帖子
public static void deleteRecord() {
try {
Scanner shuru2=new Scanner(System.in);
System.out.print("\n请输入"
+ "要删除帖子号: ");
int forumnumber2 = Integer.parseInt(shuru2.next());
try{
Connection conn=LoadForum.getConnection();
Statement stat=conn.createStatement();
String printorder=new String("select nickName,content,dataTime from messagetable where forumnumber="+forumnumber2);
ResultSet ztr=stat.executeQuery(printorder);
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * ");
while(ztr.next()){
System.out.println(" "+ztr.getString(1)+"\t"+ztr.getString(2)+"\t"+ztr.getString(3));
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * ");
}
stat.close();
conn.close();
}
catch(Exception e){
System.out.print(e);
}
Connection con2=LoadForum.getConnection();
Statement sta2=con2.createStatement();
String selSql = "Delete from messagetable where forumNumber="+forumnumber2;
sta2.executeUpdate(selSql);
System.out.print("\n帖子已成功删除 !");
System.out.println();
sta2.close();
con2.close();
}
catch (SQLException ioe) {
System.out.println("删除时出错...." + ioe);
}
catch (Exception e) {
System.out.println("错误....." + e);
}
}
public static void menuchoice() throws IOException {
if(LoadForum.userT()==-1){
System.out.println("\n**管理员**");
int choice;
int wchoice;
while(true){
System.out.println("\n1.普通权限");
System.out.println("0.管理权限");
System.out.print("请输入您的选择...: ");
Scanner shuru=new Scanner(System.in);
wchoice = shuru.nextInt();
if(wchoice==1) {
LunTanDetails.firstList();
}
if(wchoice==0){
while (true) {
System.out.println("\n2.修改帖子");
System.out.println("3.删除帖子");
System.out.println("4.跳转到登录界面");
System.out.print("请输入您的选择...: ");
shuru=new Scanner(System.in);
choice = shuru.nextInt();
switch (choice) {
case 2:
System.out.println("\n正在修改帖子......");
modifyRecord();
break;
case 3:
System.out.println("\n正在删除帖子......");
deleteRecord();
case 4:
System.out.println("\n正在跳转......");
LoadForum.forumLoadWay();
break;
default:
System.out.println("\n请重新选择");
menuchoice();
break;
}
}}
else
System.out.println("\n请输入有效值");
}
}
else
System.out.println("\n***普通会员***");
}
public static void mannagerRight() throws IOException {
Right luntanObj = new Right();
luntanObj.menuchoice();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -