jdbc displaying result problem

First of all is resultset better or rowset?.

Secondly i created a program in which i am trying to execute a simple query using rowset. My problem is i am able to display only authorid and firstname only but with no lastname. what am i doing wrong?

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import javax.sql.rowset.JdbcRowSet;

import com.sun.rowset.JdbcRowSetImpl;

publicclass JdbcRowSetTest{

staticfinal String JDBC_DRIVER ="com.mysql.jdbc.Driver";

staticfinal String DATABASE_URL ="jdbc:mysql://localhost/books";

staticfinal String USERNAME ="jhtp6";

staticfinal String PASSWORD ="jhtp6";

public JdbcRowSetTest(){

try{

Class.forName(JDBC_DRIVER);

System.out.println("Connection Established");

JdbcRowSet rowSet =new JdbcRowSetImpl();

rowSet.setUrl(DATABASE_URL);

rowSet.setUsername(USERNAME);

rowSet.setPassword(PASSWORD);

rowSet.setCommand("Select * FROM authors");

rowSet.execute();

ResultSetMetaData metaData = rowSet.getMetaData();

int number = metaData.getColumnCount();

System.out.println("Author table for Books");

for(int i=1; i<number; i++)

System.out.printf("%-8s\t", metaData.getColumnName( i ) );

System.out.println();

while(rowSet.next()){

for(int i=1; i><number; i++)

System.out.printf("%-8s\t", rowSet.getObject(i));

System.out.println();

}

}

catch (SQLException e){

e.printStackTrace();

System.exit(1);

}

catch (ClassNotFoundException e){

e.printStackTrace();

System.exit(1);

}

}

publicstaticvoid main(String[] args){

JdbcRowSetTest window =new JdbcRowSetTest();

}

}

Connection Established

Author tablefor Books

authorIDfirstName

1Harvey

2Paul

3Tem

4Sean

and here is my sql query results in mysql command prompt

mysql> select * from authors;

+-+--+-+

| authorID | firstName | lastName |

+-+--+-+

|1 | Harvey| John |

|2 | Paul| Paula|

|3 | Tem| Nieto|

|4 | Sean| Santry|

+-+--+-+

4 rows in set (0.00 sec)

[3843 byte] By [schumachera] at [2007-11-27 10:46:42]
# 1

for(int i=1; i<number; i++)

Might want to make that

>< =

instead.

Stoopid forum bug.

Message was edited by:

flounder

floundera at 2007-7-28 20:20:25 > top of Java-index,Java Essentials,New To Java...
# 2

OMG wth. duh need to get some eye glasses. thanks for pointing out flounder

schumachera at 2007-7-28 20:20:25 > top of Java-index,Java Essentials,New To Java...