jtfrier
Technical User
- Jan 12, 2006
- 85
This post is related to another post Clean up on Database
I think I got the solution to that problem. But I am having trouble figuring how how to print my HashMap to a table or XLS sheet. Here is my code This is my first java program so pleas give detail.
I think I got the solution to that problem. But I am having trouble figuring how how to print my HashMap to a table or XLS sheet. Here is my code This is my first java program so pleas give detail.
Code:
//Concatenate.java
//adds decription fields together
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
public class Concatenate
{
private static Connection connection;
private static Statement statement;
private static HashMap map = new HashMap();
static ArrayList Data;
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:manman","","");
statement = connection.createStatement();
String Query ="SELECT test1.partno, test1.lineno, test1.Desc FROM test1";
ResultSet result = statement.executeQuery(Query);
while(result.next())
{
// process results one row at a time
String partno = result.getString("partno");
String lineno = result.getString("lineno");
String desc = result.getString("Desc");
if (map.containsKey(partno))
{
Data.add ("," + desc);
}
else
{
Data = new ArrayList();
Data .add(desc);
map.put(partno,Data);
}
}
}
catch(Exception E)
{
}
}
}