📄 model_c.java
字号:
package admin.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import zd.bbs.DataBaseConnection;
public class Model_c{
private Connection con;
public Model_c(){
DataBaseConnection dbc = new DataBaseConnection() ;
this.con=dbc.getConnection();
}
//����2������
public Collection getAllModel()throws Exception{
Statement stmt=con.createStatement();
String sql="SELECT * FROM model_2";
sql=new String(sql.getBytes("ISO8859-1"), "GB2312");
ResultSet rst=stmt.executeQuery(sql);
Collection ret=new ArrayList();
while(rst.next()){
Model_from2 temp=new Model_from2();
temp.setModel_id2(rst.getInt("model_id2"));
temp.setModel_name2(rst.getString("model_name2"));
temp.setModel_ms2(rst.getString("model_ms2"));
ret.add(temp);
}
con.close();
return ret;
}
//����һ��ģ�����Ϣ
public Collection getAllModeyi()throws Exception{
Statement stmt=con.createStatement();
String sql="SELECT * FROM model_1";
sql=new String(sql.getBytes("ISO8859-1"), "GB2312");
ResultSet rst=stmt.executeQuery(sql);
Collection ret=new ArrayList();
while(rst.next()){
Model_from temp=new Model_from();
temp.setModel_id(rst.getInt("model_id"));
temp.setModel_name(rst.getString("model_name"));
ret.add(temp);
}
con.close();
return ret;
}
//���һ��ģ����Ϣ
public void addModel(Model_from model_from)throws Exception{
String sql="insert into model_1(model_name) values(?)";
// sql=new String(sql.getBytes("ISO8859-1"), "GB2312");
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setBytes(1,model_from.getModel_name().getBytes());
pstmt.execute();
}
//��Ӷ���ģ��
public void addModel2(Model_from2 model_from2)throws Exception{
String sql="insert into model_2(model_id,model_name2,model_ms2) values(?,?,?)";
//String sql="insert into model_2(model_id,model_name2,model_ms2,banzhu_name) values(?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setInt(1, model_from2.getModel_id());
pstmt.setBytes(2,model_from2.getModel_name2().getBytes());
pstmt.setBytes(3, model_from2.getModel_ms2().getBytes());
//pstmt.setBytes(4, model_from2.getBanzhu_name().getBytes());
pstmt.execute();
}
// ��id��ѯ�����
public Model_from2 getModel(int model_id2)throws Exception{
Statement stmt=con.createStatement();
String sql="select * from model_2 where model_id2="+model_id2+"";
sql=new String(sql.getBytes("ISO8859-1"), "GB2312");
ResultSet rst=stmt.executeQuery(sql);
Model_from2 model_from2=null;
while(rst.next()){
model_from2=new Model_from2();
model_from2.setModel_id2(rst.getInt("model_id2"));
model_from2.setModel_name2(rst.getString("model_name2"));
model_from2.setModel_ms2(rst.getString("model_ms2"));
}
return model_from2;
}
//���ģ����Ϣ
public void modefyModel(Model_from2 model_from2)throws Exception{
PreparedStatement pstmt=con.prepareStatement("update model_2 set model_name2=? where model_id2=?");
pstmt.setString(1, model_from2.getModel_name2());
pstmt.setInt(2,model_from2.getModel_id2());
pstmt.execute();
}
//ɾ��ģ����Ϣ
public void deleteModel(String model_id2)throws Exception{
Statement stmt=con.createStatement();
stmt.execute("delete from model_2 where model_id2="+model_id2+"");
stmt.close();
}
public void modefyModel(String model_name2,String model_ms2, String banzhuname ,String model_id2)throws Exception{
Statement stmt=con.createStatement();
stmt.execute("update model_2 set model_name2='"+model_name2+"',model_ms2='"+model_ms2+"',banzhu_name='"+banzhuname+"'where model_id2="+model_id2+"");
stmt.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -