| | |
Needs Brainstorming!!!
![]() |
•
•
Join Date: Nov 2007
Posts: 6
Reputation:
Solved Threads: 0
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.
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.
Java Syntax (Toggle Plain Text)
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); } }
Last edited by Narue; Nov 12th, 2007 at 4:14 pm. Reason: Added code tags
What is your question?
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Hardware Interrupts & 100% CPU usage (Windows NT / 2000 / XP)
- Airline Reservation System (ColdFusion)
- Backlink qulity: is geolocation of backlinks important? (Search Engine Optimization)
- AdSense Click Limit (Advertising Sales Strategies)
- dell 8400 sounds like a jet on boot (Cases, Fans and Power Supplies)
- Project (C)
- What PL is Oppropriate (IT Professionals' Lounge)
- bubble sorting in an array (C)
- Making a RPG (Geeks' Lounge)
Other Threads in the Java Forum
- Previous Thread: /Code: Hello, Please Help Me! I need help in java Project
- Next Thread: creating an instant messenger program in java
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character chat class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list loops mac map method methods mobile netbeans newbie notdisplaying number online printf problem program programming project properties qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






