📄 sort_oper.java
字号:
package com.bbs.forumsort;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import com.bbs.util.*;
public class Sort_Oper extends SortParent {
private Connection conn = null;
private Statement state = null;
private ResultSet rs = null;
private PreparedStatement pst = null;
public Sort_Oper() {
conn = DBconnection.getConnect();
}
public ArrayList getAllSort() {
ArrayList list = new ArrayList();
String sql = "select * from forum_sort";
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
SortInfo sortinfo = new SortInfo();
sortinfo.setSort_id(rs.getInt(1));
sortinfo.setSort_name(new String(rs.getString(2).getBytes(
"ISO-8859-1"), "gb2312"));
list.add(sortinfo);
}
} catch (SQLException e) {
System.out.println("查询出错" + e.getMessage());
e.printStackTrace();
return null;
} catch (UnsupportedEncodingException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return list;
}
public String insertSort() {
String returnstr = "error";
String sql = "insert into forum_sort(sort_name) values('"
+ this.getSortinfo().getSort_name() + "')";
try {
state = conn.createStatement();
int i = state.executeUpdate(sql);
if (i == 1) {
returnstr = "success";
} else {
returnstr = "error";
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return returnstr;
}
public String deleteSort(int sort_id) {
String returnstr = "error";
String sql = "delete from forum_sort where sort_id=" + sort_id;
try {
state = conn.createStatement();
int i = state.executeUpdate(sql);
if (i == 1) {
returnstr = "success";
} else {
returnstr = "error";
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return returnstr;
}
public String updateSort() {
String returnstr = "error";
String sql = "update forum_sort set sort_name='"
+ this.getSortinfo().getSort_name() + "' where sort_id="
+ this.getSortinfo().getSort_id();
try {
state = conn.createStatement();
int i = state.executeUpdate(sql);
if (i == 1) {
returnstr = "success";
} else {
returnstr = "error";
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return returnstr;
}
public SortInfo getOneRecord(int sort_id) {
SortInfo sortinfo = new SortInfo();
String sql = "select * from forum_sort where sort_id=" + sort_id;
System.out.println(sql);
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
if (rs.next()) {
sortinfo.setSort_id(rs.getInt(1));
sortinfo.setSort_name(rs.getString(2));
return sortinfo;
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -