?? typem.java
字號:
package com.vsked.services;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import com.vsked.javaBean.Typest;
import com.vsked.models.ConnectDB;
//類型方法集合
public class Typem {
private Connection conn=null;
private PreparedStatement pt=null;
private ResultSet rs=null;
//表示查詢結果集合的對象
private ArrayList results=null;
private Typest types=null;
private boolean flag=false;
//添加新聞類別
public boolean addTypes(String typ){
conn=ConnectDB.getConnectionJDBC();
try {
pt=conn.prepareStatement("insert into typest values(?)");
pt.setString(1,typ);
pt.execute();
flag=true;
} catch (Exception e) {
}finally{
ConnectDB.close();
}
return flag;
}
//修改新聞類別
public boolean modifyTypesById(Typest typ){
conn=ConnectDB.getConnectionJDBC();
try {
pt=conn.prepareStatement("update typest set typename=? where typeid=?");
pt.setString(1,typ.getTypename());
pt.setInt(2, typ.getTypeid());
int num=pt.executeUpdate();
if(num>0){
flag=true;
}
} catch (Exception e) {
}finally{
ConnectDB.close();
}
return flag;
}
// 根據編號刪除類型
public boolean deleteTypesById(int id){
conn=ConnectDB.getConnectionJDBC();
try {
pt=conn.prepareStatement("delete typest where typeid=?");
pt.setInt(1,id);
int num=pt.executeUpdate();
if(num>0){
flag=true;
}
} catch (Exception e) {
}finally{
ConnectDB.close();
}
return flag;
}
//查詢所有類型
public ArrayList getAllTypeInfo(){
results=new ArrayList();
conn=ConnectDB.getConnectionJDBC();
try {
pt=conn.prepareStatement("select * from typest order by typeid ");
rs=pt.executeQuery();
while (rs.next()) {
results.add(new Typest(rs.getInt(1),rs.getString(2)));
}
} catch (Exception e) {
}finally{
ConnectDB.close();
}
return results;
}
//查詢類型數量
public int getTypeCount(){
int count=0;
conn=ConnectDB.getConnectionJDBC();
try {
pt=conn.prepareStatement("select count(*) from typest");
rs=pt.executeQuery();
if(rs.next()) {
count=rs.getInt(1);
}
} catch (Exception e) {
}finally{
ConnectDB.close();
}
return count;
}
// 查詢類型數量
public String getTypeName(int id){
String typename="";
conn=ConnectDB.getConnectionJDBC();
try {
pt=conn.prepareStatement("select typename from typest where typeid=?");
pt.setInt(1, id);
rs=pt.executeQuery();
if(rs.next()) {
typename=rs.getString(1);
}
} catch (Exception e) {
}finally{
ConnectDB.close();
}
return typename;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -