Java and SQL Question

Associate
Joined
7 Nov 2003
Posts
584
Location
UK
Hi,
Im hoping there is some java gods around these parts to help me out a little.

Ive made a java program to interrogate an access database.
Code:
ResultSet result = db_statement.executeQuery("select * from "table_name" );

while (result.next() ){ 
output.setText(output.getText()+"ID : " + result.getInt("ID") "\t"+result.getString("Name")+"\n");

	}
Ok, so this works, it takes out the ID, and Name from the results. But if in another table i have more fields,i would have to add more result.getString, and result.getInt's and specify which column to get the result from. Very tedious, considering the amount of possible SQL commands i could execute. :(

So ... Does anyone know if there is a way to extract all the data that the sql command has output straight into my output TextField, without having to manually extract it with different java commands, it would save so much code and loads of my time :)

Any advice appreciated :) Thanks for your time peeps.
 
there isn't a way of populating a data grid type of class form the results of a resultset in java iirc. BUT you can use a for loop to loop though all of the output columns from your resultset or use an additional data layer to abstract the database access form your code.

There is a tool called mygeneration that will do this for you if you'd have chosen a decent database ;) you'll need SQL Server, Oracle, or MySql as it relies on stored procedures to do the database access (there are other databases that will do this as well).

HT
 
Back
Top Bottom