📄 navigationdao.java
字号:
package com.wuliu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.wuliu.DBConnection.DBConnection;
import com.wuliu.entity.Navigation;
/**
* @author 刘海鹏
* 导航栏DAO
*/
public class NavigationDAO {
private Connection conn = null;
private PreparedStatement ps = null;
private DBConnection dao = null;
//构造方法
public NavigationDAO() {
this.dao = new DBConnection();
}
//按类型查询
public Navigation selectNavigationByTypee(String type){
this.conn = this.dao.getConnection();
Navigation navigation = null;
try {
this.ps = this.conn.prepareStatement("select * from navigation where type=?");
this.ps.setString(1, type);
ResultSet rs = this.ps.executeQuery();
while(rs.next()){
String content = rs.getString("content");
navigation = new Navigation(type, content);
}
this.dao.closeResultSet(rs);
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.dao.closePrepStmt(ps);
try {
this.conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return navigation;
}
//修改某条信息
public boolean updateNavigation(Navigation navigation){
this.conn = this.dao.getConnection();
boolean flag= true;
try {
this.ps = this.conn.prepareStatement("update navigation set content=? where type=?");
this.ps.setString(1, navigation.getContent());
this.ps.setString(2, navigation.getType());
this.ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
flag= false;
}finally{
this.dao.closePrepStmt(ps);
try {
this.conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -