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;
		
	}
}

What's your question? Seems like you still need to work on this part

//Code goes here...

I am stuck on this line of code...

answers = rs.getString("itemKey");

it wants me to change the List to a string. So, i guess my question is do I convert the List to a String and then back to a List? Our is there something in the result set that I can use on a List?

I think you need to read a little about what a List is.

if I were you, I would add that answers to a list ..

act like you're a carpenter and take Ezzaral's advise: don't start hammering untill you know what a hammer is and what it can do. starting to hammer without understanding, I pitty your fingers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.