📄 secondlist2.java
字号:
import java.sql.*;
import java.io.*;
import java.util.*;
//myAccount 作者账号 futiehao 跟帖所属主帖的编号 content 帖子内容 title 主题名
public class SecondList2{
public static void fazhutie(String myAccount){
try{
Connection conn=getConnection();
Statement stat=conn.createStatement();
System.out.println("主题帖标题:");
Scanner scan=new Scanner(System.in);
String title=scan.next();
System.out.println("主题帖内容:");
String content=scan.next();
GregorianCalendar newtime=new GregorianCalendar();
String nowtime=newtime.getTime().toString();
String numGet=new String("select max(forumNumber) from messagetable");
ResultSet rng=stat.executeQuery(numGet);
rng.next();
int newnum=rng.getInt(1);
newnum=newnum+1;
String insertorder=new String("insert into messagetable values ("+newnum
+",'"+LoadForum.userA()+"','"+LoadForum.userN()+"','"+title+"','"+content
+"',-1,null,'"+nowtime+"')");//获取系统时间的问题,用字符串解决
stat.execute(insertorder);
System.out.println("发表主题帖成功!\n");
stat.close();
conn.close();
LunTanDetails.firstList();
}catch(Exception e){
e.printStackTrace();
}
}
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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -