Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add dummy field

Status
Not open for further replies.

DB2Problem

Programmer
Oct 17, 2002
53
US
My database table is returning years as

1999, 2000, 2001, 2002 from the year_description field. I want to assign a unique char datatype (year_code) to this.
For Example -
1, 1999
2, 2000
3, 2001

I can not modifying/add anything in the database. How can I do this in SQL or java
 
I'm not sure if this is what you want or not...if not, sorry about that, could you provide a little more information then.

Code:
import java.sql.*;
import java.util.*;

public class CreateMap
{
	public static void main (String [] args)
	{
		try
		{
			Statement statement		= null;
			Connection connection 	= null;
			ResultSet resultSet		= null;
			Map map 				= new LinkedHashMap();
			String driver 			= "sun.jdbc.odbc.JdbcOdbcDriver";
			String url 				= ("jdbc:odbc:TestDB");
			String user 			= "";
			String pass 			= "";

			Class.forName(driver);

			connection = DriverManager.getConnection(url, user, pass);
			statement = connection.createStatement();
			String selectDate = ("SELECT year_description FROM tblOrderDetal;");
			
			resultSet = statement.executeQuery (selectDate);
			int i = 1;

			while (resultSet.next())
			{
				// Add some elements
				map.put(new Integer(i),new Integer(resultSet.getInt("year_description")));
				i++;

			}

			// List the entries
			Object key;
			Object value;
			for (Iterator it=map.keySet().iterator(); it.hasNext(); )
			{
				key = it.next();
				value = map.get(key);
				System.out.println(key + "," +  value);

			}

		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}

***** OUTPUT **********

1,1999
2,2000
3,2001
4,2002
 
Thanks a lot, yes i think this is what i was looking. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top