我正在尝试以JTable
.
这是我ActionListener
的主要课程的一部分...
if(e.getSource()==jjb)
{
String j[] = null;
Vector r = new Vector();
Vector finl = new Vector();
try
{
d10.connection();
int b = d10.getclmncnt();
for(int g = 1; g<=b+1;g++)
{
j = new String[g];
}
for(int g = 1; g<=b;g++)
{
j[g] = d10.gettableclmn(g);
}
Vector v = new Vector();
for(int g = 1; g<=b;g++)
{
v.addElement(j[g]);
}
int a = d10.getrwcnt();
System.out.println("no of rows are :::: "+a);
r = d10.getalldata(b);
JTable t = new JTable(r,v);
t.setLayout(null);
TableColumn tc;
for(int hh = 0;hh<t.getColumnCount();hh++)
{
tc = t.getColumnModel().getColumn(hh);
tc.setWidth(75);
}
JScrollPane js = new JScrollPane(t);
js.setBounds(10, 100, 1000, 500);
p5.add(js);
p5.repaint();
}
catch (ClassNotFoundException e1)
{
e1.printStackTrace();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
这是我与数据库连接的课程...
public void connection()throws SQLException, ClassNotFoundException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Loaded");
Properties p = new Properties();
p.setProperty("user","system");
p.setProperty("password", "oracle10");
p.setProperty("url","jdbc:oracle:thin:@Suneel-PC:1521:XE");
c = DriverManager.getConnection(p.getProperty("url"),p.getProperty("user"),p.getProperty("password"));
System.out.println("connected");
}
public String gettableclmn(int b2)
{
String s = null;
int fh = b2;
try
{
Statement ss = c.createStatement();
ResultSet rs = ss.executeQuery("select * from data");
ResultSetMetaData rsmd = rs.getMetaData();
s = rsmd.getColumnName(fh);
System.out.println("columns names are "+rsmd.getColumnName(fh));
}
catch (SQLException e)
{
e.printStackTrace();
}
return s;
}
public int getclmncnt()
{
int h = 0;
ResultSetMetaData rsmd;
try {
Statement ss = c.createStatement();
ResultSet rs = ss.executeQuery("select * from data");
rsmd = rs.getMetaData();
h = rsmd.getColumnCount();
}
catch (SQLException e)
{
e.printStackTrace();
}
return h;
}
public Vector getalldata(int b)
{
int d = b;
String j = null;
Vector rr = new Vector();
Vector v = new Vector(d);
try
{
Statement s = c.createStatement();
ResultSet r = s.executeQuery("select * from data");
while(r.next())
{
v.add(r.getInt(1));
v.add(r.getInt(2));
v.add(r.getInt(3));
v.add(r.getInt(4));
v.add(r.getInt(5));
v.add(r.getInt(6));
v.add(r.getInt(7));
v.add(r.getInt(8));
v.add(r.getInt(9));
v.add(r.getInt(10));
v.add(r.getInt(11));
v.add(r.getString(12));
}
rr.add(v);
}
catch (SQLException e)
{
e.printStackTrace();
}
return rr;
}
public int getrwcnt()
{
ResultSet r;
int j = 0;
try
{
Statement s = c.createStatement();
r = s.executeQuery("select count (*) from data");
r.next();
j = r.getInt(1);
}
catch (SQLException e)
{
e.printStackTrace();
}
return j;
}
当我运行此代码时,只有第一个结果显示在 中JTable
,但是当我调用function d10.getrwcnt();
它时,它会以行的形式给我输出79
。我的代码有什么问题?