postgresql一览展示了数据库里的数据,怎么删除呢,代码在下面
Title.java
package cn.ac.radi.example;
import java.sql.Date;
public class Title {
private int id;
private Date createTime;
private int rainfall;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getRainfall() {
return rainfall;
}
public void setRainfall(int rainfall) {
this.rainfall = rainfall;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Title(int id,Date createTime,int rainfall) {
super();
this.id = id;
this.createTime = createTime;
this.rainfall = rainfall;
}
}
------------------------------------------------------------------------------------------------------------------------------------
TitleDAO.java
package cn.ac.radi.example;
import cn.ac.radi.example.Title;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class TitleDAO {
public List readFirstTitle(){
//调用list接口下的ArrayList类,再此需要使用泛型,因为当数据存入集合中,类型默认转换为object类型所以加入泛型,就不用后续进行强制转换了
List list =new ArrayList();
Connection con=null;
PreparedStatement psmt=null;
ResultSet rs=null;
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/myDB","postgres","postgres");
String sql="select * from rainfall2013";
psmt=con.prepareStatement(sql);
rs=psmt.executeQuery();
while(rs.next())
{
int id=rs.getInt("id");
Date createTime=rs.getDate("date");
int rainfall=rs.getInt("降雨量");
//通过创建Title实体类的对象,把行数据依次存入,之后再把行数据逐次的方法list集合中
Title tl=new Title(id, createTime,rainfall);
list.add(tl);
}
} catch (SQLException e) {
e.printStackTrace();
}finally
{
try {
if(rs!=null)
{
rs.close();
}
if(psmt!=null)
{
psmt.close();
}
if(con!=null)
{
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
}
------------------------------------------------------------------------------------------------------------------------------
titleList.jsp
Test-newsTitle
------------------------------------------------------------------------------------------------------------------------------------ |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|