📄 wenzhangmanage.java
字号:
package news_bean;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.io.*;
import java.util.*;
import filter.charConvert;
public class wenzhangManage {
static Conn conn=new Conn();
private String sql;
private ResultSet rs;
int i;
long w_id;
public ResultSet showWenzhang(){
sql = "select * from wenzhang where w_shencha=false;";
rs = conn.executeQuery(sql);
try{
if(rs.next())
{
return this.rs;
}
return null;
}catch(Exception e)
{
e.printStackTrace();
return null;
}
}
public boolean addWenzhang(long id , String nneirong , String nbiaoti){
try {
Calendar cal = Calendar.getInstance();
int year=cal.get(Calendar.YEAR);
int month=cal.get(Calendar.MONTH)+1;
int day=cal.get(Calendar.DATE);
int hour=cal.get(Calendar.HOUR_OF_DAY);
int minute=cal.get(Calendar.MINUTE);
int second=cal.get(Calendar.SECOND);
String date = new String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
charConvert c = new charConvert();
//java.util.Date d = new java.util.Date();
//SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd ",Locale.US);
String neirong = c.getString(nneirong);
String biaoti = c.getString(nbiaoti);
//System.out.print(id+" "+biaoti+" "+neirong );
java.lang.Class.forName("org.gjt.mm.mysql.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/news","root","103045");
PreparedStatement sql = connect.prepareStatement("insert into wenzhang(w_name,w_shijian,w_shencha,zuozhe) values(?,?,?,?)");
sql.setString(1,biaoti);
sql.setString(2,date);
sql.setBoolean(3,false);
sql.setLong(4,id);
int i = sql.executeUpdate();
sql.close();
if(i>0){
this.getW_ID(id, date);
//System.out.print("111111111111111111");
File f = new File("d:\\"+w_id+".txt");
f.createNewFile();
FileWriter fw = new FileWriter(f);
BufferedWriter bfw = new BufferedWriter(fw);
bfw.write(neirong,0,neirong.length());
bfw.flush();
bfw.close();
return true;
}return false;
}catch(Exception e)
{
return false;
}
}
public long getW_ID(long id,String date)
{
try{
java.lang.Class.forName("org.gjt.mm.mysql.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/news","root","103045");
PreparedStatement sql1 = connect.prepareStatement("select w_id from wenzhang where zuozhe=? and w_shijian=?;");
sql1.setLong(1,id);
sql1.setString(2,date);
rs = sql1.executeQuery();
rs.next();
w_id = rs.getLong("w_id");
System.out.println(w_id);
rs.close();
sql1.close();
connect.close();
return w_id;
}catch(Exception e)
{
e.printStackTrace();
return 0;
}
}
public boolean deleWenzhang(String id){
sql = "delete from wenzhang where w_id='"+id+"'";
i = conn.executeUpdate(sql);
if(i>0)
{
if(this.isFileExits(id))
{
File f = new File("d:\\"+id+".txt");
if(f.delete())
return true;
}
return false;
}
return false;
}
public boolean deleLanmu(long id){
sql = "delete from wenzhang where lanmu="+id+";";
System.out.println(sql);
i = conn.executeUpdate(sql);
if(i>0)
{
return true;
}
return false;
}
public boolean pizhunWenzhang(String id,String l_id)
{
System.out.print(id +" +++ "+l_id);
sql = "UPDATE wenzhang SET w_shencha="+true+" ,lanmu='"+l_id+"' where w_id="+id+";";
int i = conn.executeUpdate(sql);
if(i>0)
{
return true;
}else{
return false;
}
}
/*
*
*String str=fabiaotextarea;
String nameOfTextFile = "d:/test.txt";
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.print(str);
pw.close();
*/
public boolean isFileExits(String id)
{
try{
System.out.println(id);
File f = new File("D:\\"+id+".txt");
if(f.exists()){
System.out.println("here");
return true;
}
else
return false;
}catch(Exception e)
{
e.printStackTrace();
return false;
}
}
public ResultSet selectWenzhang(long id)
{
sql = "select * from wenzhang where w_shencha=true and lanmu="+id+" LIMIT 10;";
rs = conn.executeQuery(sql);
return rs;
}
public ResultSet showWZ(long id){
System.out.println("herr");
sql = "select w_id,w_name from wenzhang where w_shencha=true and lanmu="+id+";" ;
rs = conn.executeQuery(sql);
return rs;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -