:confused: i've been trying to get a database query to work, but so far it seems like i'm doing wrong than right. i'm suppose to use prepared statement to query it, have an option to enter userID and then have a print out of all the stocks associated with that user. with what have now i can enter the userID but the system prints only 1 stock item associated with that user and then i have to enter the userID again

Java Code:

import java.sql.*;
import java.io.*;


public class QueryStatement
{

	public static void main(String [] args)throws Exception
	{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		String url = "jdbc:odbc:StockTracker";
		Connection con = DriverManager.getConnection(url);
		ResultSet rs ;

		String user = "user";
		String Query = "SELECT u.userID, u.firstName,u.lastName, us.symbol, s.name FROM Users u, UserStocks us, Stocks s WHERE us.userID = u.userID ";

   		PreparedStatement Pstmt = con.prepareStatement(Query);
		rs = Pstmt.executeQuery();



			 //reading data from the ResultSet
			 while(rs.next())
			 {
				BufferedReader datain = new BufferedReader(new InputStreamReader(System.in));
        		System.out.println("Enter UserID: 	");
        		user = datain.readLine();
        		System.out.println("Stock holdings for User:"+"\t"+rs.getString("firstName")+"\t"+rs.getString("lastName"));
        		System.out.println("Stock - Description");
				System.out.println("-------------------------------------------------------");





				if(rs.next())
				{
					System.out.println("\t"+rs.getString("symbol")+"\t"+rs.getString("name"));
				}
			}








}}