newstable.java
来自「这是一个可以在手机客户端运行的选课系统 这个是客户端」· Java 代码 · 共 52 行
JAVA
52 行
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 + =
减小字号Ctrl + -
显示快捷键?