package pen;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class Execute {
Connection con;
//初始化连接。
private String list;
private String content;
private String title;
private String strsql;
public void setlist(String title)
{
this.title = title;
}
//获取类成员变量list的值
public String getlist()
{
return this.list;
}
public void settitle(String title)
{
this.title= title;
}
//获取类成员变量title的值
public String gettitle()
{
return this.title;
}
//设置类成员变量content的值
public void setcontent(String content)
{
this.content = content;
}
//获取类成员变量content的值
public String content()
{
return this.content;
}
public Execute()
{
String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1400;DatabaseName=xinwen";
String USER="sa";
String PWD="admin";
try
{
Class.forName(CLASSFORNAME);
con = DriverManager.getConnection(url,USER,PWD);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//在数据库中修改信息,对用户资料进行修改
public void addnews()throws Exception
{
try
{
this.strsql="insert into news ";
this.strsql=this.strsql + "(title,content,listid) ";
this.strsql=this.strsql + "values('" + this.title + "','" + this.content + "','" + this.list+ "')";
PreparedStatement pstmt=con.prepareStatement(strsql);
//pstmt.setDate(5,new java.sql.Date(new java.util.Date().getTime()));
pstmt.execute();
// con.close();
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
//查询数据库,新闻标题
public ResultSet getContact(String num)
{
try
{
Statement stm=con.createStatement();
ResultSet result=stm.executeQuery("select top 6 * from news where listid='"+num+"'order by id desc");
return result;
}
catch(Exception e)
{
}
return null;
}
}
xinwen.rar_javascript
版权申诉
113 浏览量
2022-09-21
06:33:09
上传
评论
收藏 503KB RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+