[Duplicate post. See below]

i am happy to be a member of this community. recently, i encountered some problems while i was working on a project, along the line, i thiught i should let my problems be known to the community.

The project has to be database driven application. here,i need to use a particular existing record to QUERY as per say, to retrieve the details of that record as long as it exists in the database.

please looking forward to hear from you as soon as possible.

Bellow is the excerpt of the program.

import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
import java.sql.*;

public class CarHistory extends JFrame implements ActionListener
{
	// Initializing the variables

	JLabel caption, enterlab,chassislab,imglab,message;
	JTextField chassisfield;
	JTextArea displaysearch;
	JScrollPane scroll;
	JButton search, reset;
	ImageIcon icon;
	
	Connection conect;
	StringBuffer stb;
	String sql,a;
	Statement st;
	PreparedStatement pst;
	ResultSet rset;
	ResultSetMetaData rsetmet;
	
	
	public CarHistory(String title)
	{
		super(title);
		getContentPane().setLayout(null);
		getContentPane().setBackground(Color.white);

		icon = new ImageIcon("tracklogo.jpg");
		imglab = new JLabel(icon);
		imglab.setBounds(0,0,200,100);
		getContentPane().add(imglab);

		message = new JLabel("Detail Output");
		message.setBounds(380,10,200,20);
		getContentPane().add(message);

		caption = new JLabel("CAR HISTORY");
		caption.setBounds(230,80,100,20);
		getContentPane().add(caption);

		enterlab = new JLabel("ENTER CHASSIS/VIN Number of Vehicle to get History.");
		enterlab.setBounds(20,110,340,20);
		getContentPane().add(enterlab);
		
		chassislab = new JLabel("Chassis/Vin No:");
		chassislab.setBounds(20,135,120,20);
		getContentPane().add(chassislab);

		chassisfield = new JTextField();
		chassisfield.setBounds(130,135,100,20);
		getContentPane().add(chassisfield);

		displaysearch = new JTextArea();
		//displaysearch.setBounds(350,30,430,170);
		displaysearch.setBackground(Color.pink);
		displaysearch.setForeground(Color.white);
		displaysearch.setEditable(false);
		

		scroll = new JScrollPane(displaysearch);
		scroll.setBounds(350,30,430,170);
		getContentPane().add(scroll);

		search = new JButton("SEARCH");
		search.setBounds(130,180,100,20);
		getContentPane().add(search);

		
		reset = new JButton("RESET");
		reset.setBounds(250,180,100,20);
		getContentPane().add(reset);

		search.addActionListener(this);
		reset.addActionListener(this);
	} 
	public void actionPerformed(ActionEvent ae)
	{
		if(ae.getSource()==reset)
		{
			chassisfield.setText("");
		}
			if(ae.getSource()==search)
			{
				if((chassisfield.getText()=="")||(chassisfield.getText().length()==0))
				{
					JOptionPane.showMessageDialog(null,"Please Enter Your Car Chassis Number.","Omited", JOptionPane.INFORMATION_MESSAGE);
				}
			else if(ae.getSource()==search)
			{
				try
				{
				//--------- Loading the driver manager-=------------======================

				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");	
				System.out.println("Driver Loaded.");
				conect=DriverManager.getConnection("jdbc:odbc:digit");
				System.out.println("Connection Established");
				
					st = conect.createStatement();
					sql=new String("SELECT * from CarReg where VehicleChassis_No='"+chassisfield.getText()+"'");
					rset =st.executeQuery(sql);
					while(rset.next())	
					{
						a= rset.getString("VehicleChassis_No");
						System.out.println(a);
											
						if(chassisfield.getText().equals(a))
						{
							System.out.println("yes exists");
							stb = new StringBuffer();
							rsetmet = rset.getMetaData();
							int numberOfColumns = rsetmet.getColumnCount();	
													
							for (int i =1; i<= numberOfColumns; i++)
								stb.append(rsetmet.getColumnName(i) + "\t");
								stb.append("\n");
								while (rset.next())
 								{
									for (int i = 1; i <=numberOfColumns; i++)
									stb.append(rset.getObject(i)+ "\t");
									stb.append("\n");
								}
									while (rset.next())
 									{
										for (int i = 1; i <=numberOfColumns; i++)
										stb.append(rset.getObject(i)+ "\t");
										stb.append("\n");
									}

										while (rset.next())
 										{
											for (int i = 1; i <=numberOfColumns; i++)
											stb.append(rset.getObject(i)+ "\t");
											stb.append("\n");
										}

							
										displaysearch.setText(stb.toString());
										message.setText("<<<<<   Your Car Details  >>>>>>>");	
										JOptionPane.showMessageDialog(null,"Data Retrieved");
						}
						else
						{
							JOptionPane.showMessageDialog(null, "No Such Chassis Number.");
							return;						
						}
					}	
					
					conect.close();
					st.close();
					}
					catch(Exception e){System.out.println("[SQLException:]Data Violation:ERROR."); e.printStackTrace();}
					}
		}								
	}
	public static void main(String args[])
	{
		CarHistory CH = new CarHistory("<<<<  AUTOMOBILE TRACKING SYSTEM   >>>>>");	
		CH.setSize(800,250);
		CH.setVisible(true);
		CH.setResizable(false);
		CH.setLocation(200,100);
	}
}

Thanks for showing interest.

My question actually, was centered to what method to use to retrieve my resultset as soon as i enters my car chassis number. so that the details of the car will be displayed on the textarea which i provided.

looking forward to hear from you as soon as possible.

This article has been dead for over six months. Start a new discussion instead.