Topic: 成功连接了数据库和表,显示就不会了

  Print this page

1.成功连接了数据库和表,显示就不会了 Copy to clipboard
Posted by: nogod
Posted on: 2005-01-13 20:07

在一个窗体上添加了dbString里的tableScrollPane1,在tableScrollPane1又加了个jdbTable1,还有一个jButton按纽。我们都知道jdbTable1是显示数据的。在这里我是这样用代码连接的数据库代码如下:
url="jdbc:odbc:xue";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection(url);
querystring="select * from ab";
st=conn.createStatement() ;
rs=st.executeQuery(querystring);
结果集已经保存到resultset对象里去了
代码是没有大问题的。
(我是对照一本参考书做练习,书上是用的database和querydataset两个组件连接的数据库和表,在这里我是用代码。测试是已经成功连接了数据库和表啦。)

可是,怎么让所有的数据在一点按纽后在jdbTable1上全部给显示出来,偶就不会写啦。麻烦路过的朋友,指点一下在按纽的actionperformed()方法里到底该怎么写啊。。
麻烦高人给写下。

2.Re:成功连接了数据库和表,显示就不会了 [Re: nogod] Copy to clipboard
Posted by: lcwling
Posted on: 2005-01-13 23:55

Navigating a ResultSet
We access the ResultSet one row at a time, starting at the first row and advancing one row forward at a time.Associated with the ResultSet is a cursor, a kind of pointer, which is initially set to point before the first row. To advance it to the first row and every row after that, we need to call the ResultSet's next() method. The next() method returns a Boolean value: true if it was successful in advancing to the next row, false if there are no more rows. This is the usual way to iterate through a ResultSet:

while(rs.next())
{
// Process current row, column by column
}

Once we have positioned the cursor at a valid row by calling the next() method, we use the ResultSet's getXXX methods to access the columns in the row. Each of the row's columns can be addressed in one of two ways: by the column's name or by its index, starting at 1. In general, it is most efficient to retrieve data from columns by index, in order. Like the set methods for PreparedStatement, ResultSet has many get methods.

The most commonly used are those for basic Java types and classes, such as getInt(), getLong(), getFloat(), getDouble(), getString(), getDate(), and getTime(). For each column, we need to choose the most appropriate type.

reading a row from the database into an array or vector ...

3.Re:成功连接了数据库和表,显示就不会了 [Re: nogod] Copy to clipboard
Posted by: nogod
Posted on: 2005-01-14 08:02

楼上的,俺英语不好。你这样不是折磨我吗。
楼上的,你还是说句汉语好不好啊。别说洋文,俺农民听不懂的来。

4.Re:成功连接了数据库和表,显示就不会了 [Re: nogod] Copy to clipboard
Posted by: smomo
Posted on: 2005-02-05 21:44

看jdk 下面 demo\jfc\tableexample 里的源代码,那里的程序是可以以表格的形式显示数据。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923