Add a method getListForQuery(String query) to the DatabaseManager class that will return a List of all the columns in the first row returned in the result set for the passed query. You can find out how many columns have been returned by getting a ResultSetMetaData object from the ResultSet object using the method getMetaData() method. You can then ask the ResultSetMetaData object for the number of columns by using the method getColumnCount().

What will be an ideal response?


```
/? ?
? Method t o e x e c u t e a q u e r y and r e t u r n a l i s t o f s t r i n g s
? f o r t h e f i r s t r e t u r n e d row
? @param q u e r y t h e q u e r y t o e x e c u t e
? @return l i s t o f s t r i n g s f o r t h e d a t a i n t h e f i r s t
? r e t u r n e d row , t h e l i s t may be empty
?/
public L i s t g e t L i s t F o r Q u e r y ( S t r i n g query )
{
L i s t r e s u l t L i s t = new A r r a y L i s t ( ) ;
// t r y t h e f o l l o w i n g
try {
// open t h e c o n n e c t i o n t o t h e d a t a b a s e
Connection c o n n e c t i o n =
DriverManager . g e t C o n n e c t i o n ( t h i s . u r l S t r ) ;
// c r e a t e a s t a t e m e n t
Statement s t a t e m e n t = c o n n e c t i o n . c r e a t e S t a t e m e n t ( ) ;
// e x e c u t e t h e q u e r y
R e s u l t S e t r s = s t a t e m e n t . executeQuery ( query ) ;
// f i n d o u t how many columns a r e i n t h e r e s u l t
ResultSetMetaData rsmd = r s . getMetaData ( ) ;
i n t numCols = rsmd . getColumnCount ( ) ;
// p r i n t o u t t h e r e s u l t s
i f ( r s . next ( ) )
{
f o r ( in t i = 1 ; i <= numCols ; i ++)
r e s u l t L i s t . add ( r s . g e t S t r i n g ( i ) ) ;
}
// c l o s e e v e r y t h i n g
rs . close ( ) ;
statement . c l o s e ( ) ;
connection . close ( ) ;
} catch ( SQLException ex ) {
SimpleOutput . showError ( ” Trouble with t h e d a t a b a s e ” + u r l S t r ) ;
ex . p r i n t S t a c k T r a c e ( ) ;
}
return r e s u l t L i s t ;
}
```

Computer Science & Information Technology

You might also like to view...

Write a short program that accepts an arbitrary number of command line arguments, and prints out those containing the character 'z'.

What will be an ideal response?

Computer Science & Information Technology

_____ is an XML vocabulary used for displaying and organizing musical notation and lyrics.

A. MML B. RSS C. SMIL D. CML

Computer Science & Information Technology

The UNIX process scheduling algorithm picks the process that will run in the shortest amount of time to be run first.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Instead of hard coding the actual filename and file path, you could prompt the user for the name of the file using subclasses of the FileDialog class.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology