新手遇到MyEclipse提示[如标题]错误, 代码如下
其中:Vector<String> ziduan; 这个加上<String>进行泛型, 就不再提示标题错误
但对Vector jilu; 就不知道怎么解决了, 请赐教!
{我尝试了Vector <Vector>jilu;方法, 下面的不会有提示, 但定义的这一行,还会有提示 }
import java.sql.*;
import java.util.*;
import javax.swing.table.*;;
class StuQuery extends AbstractTableModel{
Vector<String> ziduan;
Vector jilu;
PreparedStatement ps = null;
Connection cn = null;
ResultSet rs = null;
Statement sm = null;
public int getRowCount(){
return this.jilu.size();
}
public int getColumnCount(){
return this.ziduan.size();
}
public String getColumnName(int e){
return (String)this.ziduan.get(e);
}
public Object getValueAt(int hang,int lie){
return ((Vector)this.jilu.get(hang)).get(lie);
}
StuQuery(){
this.sqlquery("select * from student");
}
StuQuery(String sql){
this.sqlquery(sql);
}
public void sqlquery(String sql){
ziduan = new Vector<String>();
ziduan.add("编号");
ziduan.add("姓名");
ziduan.add("性别");
ziduan.add("年龄");
ziduan.add("籍贯");
ziduan.add("专业");
jilu = new Vector();
try{
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","root");
ps = cn.prepareStatement(sql);
rs = ps.executeQuery();
//sm = cn.createStatement();
//rs = sm.executeQuery(sql);
while(rs.next()){
Vector<String> hang = new Vector<String>();
hang.add(rs.getString("no"));
hang.add(rs.getString("xingming"));
hang.add(rs.getString("sex"));
hang.add(rs.getString("age"));
hang.add(rs.getString("jiguan"));
hang.add(rs.getString("zhuanye"));
jilu.add(hang);
}
}
catch(Exception e){
}
finally{
try{
if(rs != null){rs.close();}
if(ps != null){ps.close();}
if(cn != null){cn.close();}
}
catch(Exception e2){}
}
}
}
------解决方案--------------------
给泛型里面的Vector继续添加泛型<String>
Vector<Vector<String>> jilu;
jilu = new Vector<Vector<String>>();