
import java.util.*;

import jet.util.*;
import java.sql.*;

/**
 * <code>ParamTest</code> provides an example of how to populate a parameter list using a DBMS query.
 */
public class ParamTest implements ImportParamValues
{
	
	public ParamTest()
	{
		;
	}

	public Hashtable promptValues(String paramsName[])
	{
		
		String name;
		Vector<String> values;
		Hashtable<String, Vector<String>> ret = new Hashtable<String, Vector<String>>();
		
		Connection connection=null;
		Statement staobj = null;
	  	ResultSet rs = null;
		String sq;
		try
		{
			//register the driver
			Class.forName("org.hsqldb.jdbcDriver");
			//build the connection to the database
			connection = DriverManager.getConnection("jdbc:hsqldb:C:/JReport/Designer/Demo/db/SampleDB", "sa", "");
			
			// Pass an SQL statement
			staobj=connection.createStatement();
			// List all the ship dates
			sq="SELECT distinct ShipDate FROM orders; ";
			boolean bsql=staobj.execute(sq);//run the above SQL statement
			if(bsql)
			{
				rs= staobj.getResultSet();	//get the resultset
			}
			for ( int t = paramsName.length; --t >= 0; )
			{
				name = paramsName[t];
				if ( name.compareToIgnoreCase("p_StartDate")==0 )
				{
					values = new Vector<String>();
					while(rs.next())
					{

 						java.sql.Date myDate=rs.getDate(1);
						values.addElement(myDate.toString());//set each record to the vector
					}
					ret.put(name, values);
				}	
				else
				{
				}
			}
			rs.close();	//release the resultset
			staobj.close();   //close the SQL statement
			connection.close(); //close the connection to the database
			return ret;
		}	
		catch(Exception e)
		{
			System.out.println(e.getMessage());
		}
		return null;
		
		
		
	}
}
