📄 newstable.java
字号:
package jdbc;
import java.sql.*;
public class NewsTable
{
private String command=null;
private Statement statement=null;
public NewsTable(Statement statement)
{
this.statement=statement;
}
public int insert(int newsID,String category,String date,String title,String detail) throws SQLException
{
command="INSERT INTO NewsTable" +" VALUES ("+newsID+",'"+category+"','"+date+"','"+title+"','"+detail+"')";
return statement.executeUpdate(command);
}
public int delete(int newsID) throws SQLException
{
command="DELETE FROM NewsTable WHERE newsID="+newsID;
return statement.executeUpdate(command);
}
public int update(int newsID,String category,String date,String title,String detail) throws SQLException
{
command="UPDATE newsTable SET category='"+category+"',newsdate='"+date+"',title='"+title+"',detail='"+detail+"' WHERE newsID="+newsID;
return statement.executeUpdate(command);
}
public ResultSet select(int newsID) throws SQLException
{
if(newsID<0)
command="SELECT * FROM newsTable";
else
command="SELECT * FROM newsTable WHERE ID="+newsID;
return statement.executeQuery(command);
}
public ResultSet selectCategory() throws SQLException
{
command="SELECT DISTINCT CATEGORY FROM NEWSTABLE";
return statement.executeQuery(command);
}
public ResultSet selectTitle(String category) throws SQLException
{
command="SELECT * FROM NEWSTABLE WHERE CATEGORY='"+category+"'";
return statement.executeQuery(command);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -