📄 database.java
字号:
package ntsky.news;
import java.sql.*;
import ntsky.database.*;
public class Database{
private int sum;
private int classid;
private int id;
private ResultSet rs = null;
private int counter;
//文章的总值(数据库)(判断有无记录,如没有的话就要求先添加记录)
public int sum() throws Exception{
String sql = "select count(articleid) as t from article where state=1 and classid=4;";
DBConnect dbc = new DBConnect();
rs=dbc.executeQuery(sql);
if(rs != null){
rs.next();
sum = rs.getInt("t");
return sum;
}
else{
return 0;
}
}
//文章的总值(oracle)(判断有无记录,如没有的话就要求先添加记录)
public int sum_oracle() throws Exception{
String sql = "select count(articleid) as t from article where state=1 and classid=4 and id=9;";
DBConnect dbc = new DBConnect();
rs=dbc.executeQuery(sql);
if(rs != null){
rs.next();
sum = rs.getInt("t");
return sum;
}
else{
return 0;
}
}
//文章的总值(mysql)(判断有无记录,如没有的话就要求先添加记录)
public int sum_mysql() throws Exception{
String sql = "select count(articleid) as t from article where state=1 and classid=4 and id=10;";
DBConnect dbc = new DBConnect();
rs=dbc.executeQuery(sql);
if(rs != null){
rs.next();
sum = rs.getInt("t");
return sum;
}
else{
return 0;
}
}
//文章的总值(mssql)(判断有无记录,如没有的话就要求先添加记录)
public int sum_mssql() throws Exception{
String sql = "select count(articleid) as t from article where state=1 and classid=4 and id=11;";
DBConnect dbc = new DBConnect();
rs=dbc.executeQuery(sql);
if(rs != null){
rs.next();
sum = rs.getInt("t");
return sum;
}
else{
return 0;
}
}
//时间
public ResultSet rs_time() throws Exception{
String sql = "select time,classid,id from article where classid=4 and state=1 order by time desc limit 0,1;";
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
return rs;
}
//oracle时间
public ResultSet rs_time_oracle() throws Exception{
String sql = "select time,classid,id from article where state=1 and classid=4 and id=9 order by time desc limit 0,1;";
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
return rs;
}
//mysql时间
public ResultSet rs_time_mysql() throws Exception{
String sql = "select time,classid,id from article where state=1 and classid=4 and id=10 order by time desc limit 0,1;";
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
return rs;
}
//mssql 时间
public ResultSet rs_time_mssql() throws Exception{
String sql = "select time,classid,id from article where state=1 and classid=4 and id=11 order by time desc limit 0,1;";
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
return rs;
}
//最新的文章(oracle)
public ResultSet rs_new_oracle(){
String sql = "select articleid,title,date from article where state=1 and classid=4 and id=9 order by time desc limit 0,6;";
try{
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.print("rs_new" +e.getMessage());
}
return rs;
}
//最新的文章(mysql)
public ResultSet rs_new_mysql(){
String sql = "select articleid,title,date from article where state=1 and classid=4 and id=10 order by time desc limit 0,6;";
try{
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.print("rs_new" +e.getMessage());
}
return rs;
}
//最新的文章(mssql)
public ResultSet rs_new_mssql(){
String sql = "select articleid,title,date from article where state=1 and classid=4 and id=11 order by time desc limit 0,6;";
try{
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.print("rs_new" +e.getMessage());
}
return rs;
}
//点击次数
public ResultSet rs_hot(){
String sql = "select articleid,title from article where state=1 and classid=4 order by hits desc limit 0,10;";
try{
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.print("rs_hot" +e.getMessage());
}
return rs;
}
//关闭指针
public void close() throws Exception{
if(rs != null){
rs.close();
rs = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -