项目:货物管理系统的显示
工具:netbean
问题:数据库连接出错
解决方法:所使用的数据库驱动包太新,更换数据库驱动包版本
问题:查询货物的时候只能查询英文的货物,不能查询中文
解决方法:url后面参数添加:?useUnicode=true&characterEncoding=UTF-8
问题:如何将数据库中的信息显示在表格里面
DefaultTableModel dtm=(DefaultTableModel) this.tblProduct.getModel();
将list中一个对象的内容放到一个vector对象中,dtm可以添加一个vecotr对象(dtm.addRow()),循环遍历list,
vector用法:
vector与list用法基本相似
Vector的创建:Vertor v=new Vector();
向Vector中添加元素:v.add("");
从Vector中删除元素:v.remove():可按索引,也可按内容删除
问题:如果第一次查询成功之后进行第二次查询,第二次的结果会追加到一次后面
解决方法:
当执行搜索功能在显示之前进行检查,如果表格中有数据,将表格中的数据删除
while(dtm.getRowCount()>0){
dtm.removeRow(0);
}
数据库查询功能:concat将两个字符串连接
"select * from student where concat(name,class) like ?"
防止查询输入的数据为空,如果为空显示所有的数据
ptmt.setString(1, "%"+str+"%");
关闭数据库连接:
public static void close(Connection con,Statement st,ResultSet rs){
if(con != null || st != null || rs != null){
try {
con.close();
st.close();
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
!!调错建立数据库字段不要使用关键字,会报错