I posted this out here yesterday and received several great responses using an ArrayList. During a code review it was suggested that a use a List<Sting> for the reusultset. Any Ideas would be welcomed. Thank you for all of your responses yesterday...
public List<String> getAnswers() throws DAOException, SQLException{
//This still needs work
String testName = "test", formName = "form";
String sql = "select item, itemkey from dbo.TestMaster " +
"where TestName = ? and FormName = ? " +
"order by item ";
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<String> answers = null;
try {
//Define the db to connect to
String dbConnect = "jdbc:sqlserver://MPSQL8B\\INST2;DatabaseName=iTest_Qa_UT;" + " integratedSecurity=false;";
//Fetch the sql class
String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//Create new instance of class
try {
Class.forName(driverClass).newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Define User name and password...
String uName = "asdasd";
String pWord = "asdasd";
//Connection result = null;
//Login to the db
conn = DriverManager.getConnection(dbConnect, uName, pWord);
//Statement to submit sql
ps = conn.prepareStatement(sql);
ps.setString(1, testName);
ps.setString(2, formName);
rs = ps.executeQuery();
while ( rs.next()) {
//Code goes here...
}
}finally {
release(rs, ps, conn);
}
return answers;
}
}