• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Java:sql using result set type of class?

Hi
What way should I write the java code to do sql when the out come should only be a bunch of fields to be displayed in a JSF type  JSP? As opposed to a List maybe or as opposed to an ArrayList. Can I get some type example?
Thank you
0
coolgem
Asked:
coolgem
  • 3
  • 3
1 Solution
 
InteractiveMindCommented:
Am not entirely clear; could you elaborate?
0
 
coolgemAuthor Commented:
Can I get an example of a java class that does sql and places the result into some setters?
Thank you
0
 
InteractiveMindCommented:
Will the result be for just a single column, or for multiple?
Can you also expand a little on the "setters"; a particular data type?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
coolgemAuthor Commented:
single column ... string fields and a text field.
thank you
0
 
InteractiveMindCommented:
Perform the query, the result will be returned as a ResultSet instance; call this instance's getArray() method, and specify the required column as a parameter (either as an index—int, or column name—String).


// shove this stuff inside a try{} scope.

Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ;
Connection conn = DriverManager.getConnection( "jdbc:odbc:MyDataBase", "", "" ) ; // db, username, password

Statement st = conn.createStatement() ;

ResultSet rec = st.executeQuery( "SELECT column_name FROM table WHERE something_is_true" ) ;

String [] rows = (String [] ) rec.getArray( 1 ) ;  // 1 = the first column

st.close() ;



You now have the results in a String array, caleld 'rows'.
0
 
coolgemAuthor Commented:
thank you very much have a great weekend!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now