?? dao.java
字號(hào):
package cn.Blogonline;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.StringTokenizer;
import java.util.Vector;
public class DAO {
public void InsertUser() { // 插入用戶
}
/*--------------------------------------分界線--------------------------------------*/
public void InsertFeedback() { // 插入留言
}
/*--------------------------------------分界線--------------------------------------*/
public void InsertArticle() { // 插入文章
}
/*--------------------------------------分界線--------------------------------------*/
public void InsertLinksForBlogId(LinksBean lb){ //根據(jù)blogid查詢友情鏈接
String url = "insert into links values('"+lb.getName()+"','"+lb.getUrl()+
"',"+lb.getBlogid()+")";
DBcon db = new DBcon();
// System.out.println(url);
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
stmt.executeUpdate(url);
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/*--------------------------------------分界線--------------------------------------*/
public void DeleteSortFromID(String id) {
String url = "delete from sort where id = " + id;
DBcon db = new DBcon();
// System.out.println(url);
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
stmt.executeUpdate(url);
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/*--------------------------------------分界線--------------------------------------*/
public void DeleteLinkFromID(String id){
String url = "delete from links where id = " + id;
DBcon db = new DBcon();
// System.out.println(url);
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
stmt.executeUpdate(url);
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/*--------------------------------------分界線--------------------------------------*/
public void InsertSort(SortBean sort) {
String url = "insert into sort values('" + sort.getName() + "',"
+ sort.getBlogid() + ")";
DBcon db = new DBcon();
// System.out.println(url);
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
stmt.executeUpdate(url);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/*--------------------------------------分界線--------------------------------------*/
public Vector SeachSortFromBlogId(String id) { // 通過blog編號(hào)查詢文章類別
Vector v = new Vector();
Vector temp = null;
String url = "select name,id from sort where blogid = " + id;
DBcon db = new DBcon();
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(url);
while (rs.next()) {
temp = new Vector();
temp.add(rs.getString(1));
temp.add(rs.getString(2));
v.add(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return v;
}
/*--------------------------------------分界線--------------------------------------*/
public Vector SeachBlogFromID(String id) { // 通過id查詢
Vector v = new Vector();
Vector temp = null;
String url = "select username,image from blog where id=" + id;
// System.out.println(url);
DBcon db = new DBcon();
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(url);
while (rs.next()) {
temp = new Vector();
temp.addElement(rs.getString(1));
temp.addElement(rs.getString(2));
v.add(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return v;
}
/*--------------------------------------分界線--------------------------------------*/
public Vector SeachArticleFromSortID(String sortid) { // 通過Sortid查詢文章標(biāo)題
Vector v = new Vector();
Vector temp = null;
String url = "select id,title,pubtime from article where sortid = " + sortid;
DBcon db = new DBcon();
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(url);
while (rs.next()) {
temp = new Vector();
temp.add(rs.getString(1));
temp.add(rs.getString(2));
temp.add(rs.getString(3));
v.add(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return v;
}
/*--------------------------------------分界線--------------------------------------*/
public void UpdateBlogSelf(BlogSelf blog) { // 更新blog個(gè)人基本信息
String url = "update blog set username = '" + blog.getUsername()
+ "',password = '" + blog.getPassword() + "',subject = '"
+ blog.getSubject() + "',email = '" + blog.getEmail()
+ "',uname = '" + blog.getUname() + "',age = '" + blog.getAge()
+ "',works = '" + blog.getWorks() + "',six ='" + blog.getSix()
+ "',likes = '" + blog.getLikes() + "' where id = "
+ blog.getId();
// System.out.println(url);
DBcon db = new DBcon();
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
stmt.executeUpdate(url);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
/*--------------------------------------分界線--------------------------------------*/
public void UpdateBlogLogo(BlogSelf blog){ //更新個(gè)人logo
String url = "update blog set image = '"+blog.getImage()+"' where id = "+blog.getId();
DBcon db = new DBcon();
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
stmt.executeUpdate(url);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
/*--------------------------------------分界線--------------------------------------*/
/*--------------------------------------分界線--------------------------------------*/
public Vector SeachLinksFromBlogID(String id){ //通過blogid查詢友情連接
Vector v = new Vector();
Vector temp = null;
String url = "select id,name,url from links where blogid=" + id;
// System.out.println(url);
String s = "";
DBcon db = new DBcon();
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(url);
while (rs.next()) {
temp = new Vector();
temp.add(rs.getString(1));
temp.add(rs.getString(2));
temp.add(rs.getString(3));
v.add(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return v;
}
/*--------------------------------------分界線--------------------------------------*/
public Vector SeachAContenFromID(String id){ //查詢文章內(nèi)容
Vector v = new Vector();
Vector temp = new Vector();
String url = "select content from article where id = " + id;
DBcon db = new DBcon();
try {
Connection con = db.getCon();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(url);
if (rs.next()) {
temp.add(id);
temp.add(rs.getString(1));
v.add(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return v;
}
/*--------------------------------------分界線--------------------------------------*/
public static void main(String[] args) {
DAO d = new DAO();
SortBean b = new SortBean();
b.setBlogid("2");
b.setName("隨便寫");
System.out.println(d.SeachLinksFromBlogID("3"));
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -