📄 motherboardsdao.java~58~
字号:
package pcdiysystem.Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import pcdiysystem.Beans.MotherboardsBean;
import javax.swing.JOptionPane;
import pcdiysystem.Panel.EditPanel;
import javax.swing.table.TableModel;
/**
* <p>Title: 自助装机系统</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author kamiiiyu
* @version 1.0
*/
public class MotherboardsDAO {
public static final int COMPONENTLISTPANEL = 0;
public static final int EDITPANEL = 1;
private EditPanel epObj;
public MotherboardsDAO() {
}
public MotherboardsDAO(EditPanel epObj) {
this.epObj = epObj;
}
public Vector getBaseInfomation(String manufacturer, int panel) {
Vector list = new Vector();
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet resultSet = null;
try {
dbConnection = ConnectionManager.getConnection();
if (dbConnection != null)
System.out.println("OK!");
String proList = "select p.* from motherboards as p left outer join Manufacturersofmotherboard as ma on ma.Manufacturerid=p.manufacturerid where ma.manufacturer=?";
pStatement = dbConnection.prepareStatement(proList);
pStatement.setString(1, manufacturer);
resultSet = pStatement.executeQuery();
while (resultSet.next()) {
MotherboardsBean pb = new MotherboardsBean();
switch (panel) {
case 0:
break;
case 1:
pb.setRecord(resultSet.getString(1));
}
pb.setRecord(resultSet.getString(3));
pb.setRecord(resultSet.getString(4));
pb.setRecord(resultSet.getString(5));
pb.setRecord(resultSet.getString(6));
pb.setRecord(resultSet.getString(7));
//switch(panel){
//case 0:break;
//case 1:
pb.setRecord(resultSet.getString(8));
//}
pb.setRecord(resultSet.getString(9));
pb.setRecord(resultSet.getString(10));
list.add(pb.getRecord());
}
}
catch (SQLException ex) {
}
finally {
ConnectionManager.closeResultSet(resultSet);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
return list;
}
public boolean updateRecord(int recordId, Vector updateData) {
Vector list = new Vector();
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet resultSet = null;
try {
dbConnection = ConnectionManager.getConnection();
if (dbConnection != null)
System.out.println("OK!");
String ps = "update motherboards set type=?,socket=?,chipset=?,compatiblecpu=?,videointerface=?,description=?,storage=?,price=? where id=?";
pStatement = dbConnection.prepareStatement(ps);
int temp = updateData.size();
for (int i = 0; i < temp; i++) {
pStatement.setString(i + 1, String.valueOf(updateData.get(i)));
}
pStatement.setInt(temp + 1, recordId);
int rowCount = pStatement.executeUpdate();
return true;
}
catch (SQLException ex) {
System.out.println("uerr");
return false;
}
finally {
ConnectionManager.closeResultSet(resultSet);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
}
public boolean deleteRecord(int recordId) {
Vector list = new Vector();
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet resultSet = null;
try {
dbConnection = ConnectionManager.getConnection();
if (dbConnection != null)
System.out.println("OK!");
String ps = "delete from motherboards where id=?";
pStatement = dbConnection.prepareStatement(ps);
pStatement.setInt(1, recordId);
int rowCount = pStatement.executeUpdate();
return true;
}
catch (SQLException ex) {
System.out.println("derr");
return false;
}
finally {
ConnectionManager.closeResultSet(resultSet);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
}
public boolean insertFile(String manufacturerId, Vector insertData) {
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet resultSet = null;
try {
dbConnection = ConnectionManager.getConnection();
if (dbConnection != null)
System.out.println("OK!");
String ps = "insert into motherboards(manufacturerId,type,socket,chipset,compatiblecpu,videointerface,[description],storage,price)values(?,?,?,?,?,?,?,?,?)";
MotherboardsBean mb = new MotherboardsBean();
mb.setDataOfTable(insertData);
for (int i = 0; i < mb.getDataOfTable().size(); i++) {
pStatement = dbConnection.prepareStatement(ps);
pStatement.setString(1, manufacturerId);
for (int j = 0; j < ( (Vector) mb.getDataOfTable().get(i)).size(); j++) {
pStatement.setString(j + 2,
String.valueOf( ( (Vector) mb.getDataOfTable().
get(i)).get(j)));
}
int rowCount = pStatement.executeUpdate();
pStatement = null;
}
return true;
}
catch (SQLException ex) {
System.out.println("ferr");
return false;
}
finally {
ConnectionManager.closeResultSet(resultSet);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
}
public Vector getDataFromTableMOdel(TableModel dtm) {
MotherboardsBean mb = new MotherboardsBean();
int rowCount = dtm.getRowCount();
int columnCount = dtm.getColumnCount();
for (int i = 0; i < rowCount; i++) {
Vector tdTemp = new Vector();
for (int j = 1; j < columnCount; j++) {
Object td = dtm.getValueAt(i, j);
tdTemp.add(td);
}
mb.setFile(tdTemp);
}
return mb.getFile();
}
public boolean isPriceFormatCorrect(String price) {
MotherboardsBean mb = new MotherboardsBean();
mb.setPrice(price);
if (!mb.getPrice().startsWith("¥")) {
JOptionPane.showMessageDialog(epObj, "请以“¥”为首字符输入价格", "非法输入!",
JOptionPane.ERROR_MESSAGE);
return false;
}
else {
String main = mb.getPrice().substring(1);
try {
float num = Float.parseFloat(main);
}
catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(epObj, "符号“¥”后面只允许输入数字!", "非法输入!",
JOptionPane.ERROR_MESSAGE);
return false;
}
}
return true;
}
public Vector getDataInblurQuery(String keyword) {
keyword = "%" + keyword + "%";
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet resultSet = null;
try {
dbConnection = ConnectionManager.getConnection();
if (dbConnection != null)
System.out.println("OK!");
String proList = "select * from motherboards where [description] like ?";
pStatement = dbConnection.prepareStatement(proList);
pStatement.setString(1, keyword);
resultSet = pStatement.executeQuery();
MotherboardsBean mb = new MotherboardsBean();
while (resultSet.next()) {
MotherboardsBean pb = new MotherboardsBean();
//pb.setRecord(resultSet.getString(1));
//pb.setRecord(resultSet.getString(2));
pb.setRecord(resultSet.getString(3));
pb.setRecord(resultSet.getString(4));
pb.setRecord(resultSet.getString(5));
pb.setRecord(resultSet.getString(6));
pb.setRecord(resultSet.getString(7));
//pb.setRecord(resultSet.getString(8));
pb.setRecord(resultSet.getString(9));
pb.setRecord(resultSet.getString(10));
mb.setFile(pb.getRecord());
}
return mb.getFile();
}
catch (SQLException ex) {
System.out.println("qErr");
return null;
}
finally {
ConnectionManager.closeResultSet(resultSet);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
}
public Vector getDataInblurQuery(String[] keywords) {
int count = keywords.length;
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet resultSet = null;
try {
dbConnection = ConnectionManager.getConnection();
if (dbConnection != null)
System.out.println("OK!");
String proList = "select * from motherboards where [description] like ?";
for (int i = 1; i < count; i++) {
proList = proList + " and [description] like ? ";
}
pStatement = dbConnection.prepareStatement(proList);
for (int i = 0; i < count; i++) {
pStatement.setString(i + 1, keywords[i] = "%" + keywords[i] + "%");
}
resultSet = pStatement.executeQuery();
MotherboardsBean mb = new MotherboardsBean();
while (resultSet.next()) {
MotherboardsBean pb = new MotherboardsBean();
//pb.setRecord(resultSet.getString(1));
//pb.setRecord(resultSet.getString(2));
pb.setRecord(resultSet.getString(3));
pb.setRecord(resultSet.getString(4));
pb.setRecord(resultSet.getString(5));
pb.setRecord(resultSet.getString(6));
pb.setRecord(resultSet.getString(7));
pb.setRecord(resultSet.getString(8));
pb.setRecord(resultSet.getString(9));
pb.setRecord(resultSet.getString(10));
mb.setFile(pb.getRecord());
}
return mb.getFile();
}
catch (SQLException ex) {
System.out.println("qErr");
return null;
}
finally {
ConnectionManager.closeResultSet(resultSet);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -