Needs Brainstorming!!!

Reply

Join Date: Nov 2007
Posts: 6
Reputation: princestasnley is an unknown quantity at this point 
Solved Threads: 0
princestasnley princestasnley is offline Offline
Newbie Poster

Needs Brainstorming!!!

 
0
  #1
Nov 12th, 2007
[Duplicate post. See below]
Last edited by Narue; Nov 12th, 2007 at 4:16 pm. Reason: Duplicate
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: princestasnley is an unknown quantity at this point 
Solved Threads: 0
princestasnley princestasnley is offline Offline
Newbie Poster

Troubleshoot Now! Now!! Now!!! Please......

 
0
  #2
Nov 12th, 2007
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.
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.event.*;
  4. import javax.swing.*;
  5. import java.sql.*;
  6.  
  7. public class CarHistory extends JFrame implements ActionListener
  8. {
  9. // Initializing the variables
  10.  
  11. JLabel caption, enterlab,chassislab,imglab,message;
  12. JTextField chassisfield;
  13. JTextArea displaysearch;
  14. JScrollPane scroll;
  15. JButton search, reset;
  16. ImageIcon icon;
  17.  
  18. Connection conect;
  19. StringBuffer stb;
  20. String sql,a;
  21. Statement st;
  22. PreparedStatement pst;
  23. ResultSet rset;
  24. ResultSetMetaData rsetmet;
  25.  
  26.  
  27. public CarHistory(String title)
  28. {
  29. super(title);
  30. getContentPane().setLayout(null);
  31. getContentPane().setBackground(Color.white);
  32.  
  33. icon = new ImageIcon("tracklogo.jpg");
  34. imglab = new JLabel(icon);
  35. imglab.setBounds(0,0,200,100);
  36. getContentPane().add(imglab);
  37.  
  38. message = new JLabel("Detail Output");
  39. message.setBounds(380,10,200,20);
  40. getContentPane().add(message);
  41.  
  42. caption = new JLabel("CAR HISTORY");
  43. caption.setBounds(230,80,100,20);
  44. getContentPane().add(caption);
  45.  
  46. enterlab = new JLabel("ENTER CHASSIS/VIN Number of Vehicle to get History.");
  47. enterlab.setBounds(20,110,340,20);
  48. getContentPane().add(enterlab);
  49.  
  50. chassislab = new JLabel("Chassis/Vin No:");
  51. chassislab.setBounds(20,135,120,20);
  52. getContentPane().add(chassislab);
  53.  
  54. chassisfield = new JTextField();
  55. chassisfield.setBounds(130,135,100,20);
  56. getContentPane().add(chassisfield);
  57.  
  58. displaysearch = new JTextArea();
  59. //displaysearch.setBounds(350,30,430,170);
  60. displaysearch.setBackground(Color.pink);
  61. displaysearch.setForeground(Color.white);
  62. displaysearch.setEditable(false);
  63.  
  64.  
  65. scroll = new JScrollPane(displaysearch);
  66. scroll.setBounds(350,30,430,170);
  67. getContentPane().add(scroll);
  68.  
  69. search = new JButton("SEARCH");
  70. search.setBounds(130,180,100,20);
  71. getContentPane().add(search);
  72.  
  73.  
  74. reset = new JButton("RESET");
  75. reset.setBounds(250,180,100,20);
  76. getContentPane().add(reset);
  77.  
  78. search.addActionListener(this);
  79. reset.addActionListener(this);
  80. }
  81. public void actionPerformed(ActionEvent ae)
  82. {
  83. if(ae.getSource()==reset)
  84. {
  85. chassisfield.setText("");
  86. }
  87. if(ae.getSource()==search)
  88. {
  89. if((chassisfield.getText()=="")||(chassisfield.getText().length()==0))
  90. {
  91. JOptionPane.showMessageDialog(null,"Please Enter Your Car Chassis Number.","Omited", JOptionPane.INFORMATION_MESSAGE);
  92. }
  93. else if(ae.getSource()==search)
  94. {
  95. try
  96. {
  97. //--------- Loading the driver manager-=------------======================
  98.  
  99. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  100. System.out.println("Driver Loaded.");
  101. conect=DriverManager.getConnection("jdbc:odbc:digit");
  102. System.out.println("Connection Established");
  103.  
  104. st = conect.createStatement();
  105. sql=new String("SELECT * from CarReg where VehicleChassis_No='"+chassisfield.getText()+"'");
  106. rset =st.executeQuery(sql);
  107. while(rset.next())
  108. {
  109. a= rset.getString("VehicleChassis_No");
  110. System.out.println(a);
  111.  
  112. if(chassisfield.getText().equals(a))
  113. {
  114. System.out.println("yes exists");
  115. stb = new StringBuffer();
  116. rsetmet = rset.getMetaData();
  117. int numberOfColumns = rsetmet.getColumnCount();
  118.  
  119. for (int i =1; i<= numberOfColumns; i++)
  120. stb.append(rsetmet.getColumnName(i) + "\t");
  121. stb.append("\n");
  122. while (rset.next())
  123. {
  124. for (int i = 1; i <=numberOfColumns; i++)
  125. stb.append(rset.getObject(i)+ "\t");
  126. stb.append("\n");
  127. }
  128. while (rset.next())
  129. {
  130. for (int i = 1; i <=numberOfColumns; i++)
  131. stb.append(rset.getObject(i)+ "\t");
  132. stb.append("\n");
  133. }
  134.  
  135. while (rset.next())
  136. {
  137. for (int i = 1; i <=numberOfColumns; i++)
  138. stb.append(rset.getObject(i)+ "\t");
  139. stb.append("\n");
  140. }
  141.  
  142.  
  143. displaysearch.setText(stb.toString());
  144. message.setText("<<<<< Your Car Details >>>>>>>");
  145. JOptionPane.showMessageDialog(null,"Data Retrieved");
  146. }
  147. else
  148. {
  149. JOptionPane.showMessageDialog(null, "No Such Chassis Number.");
  150. return;
  151. }
  152. }
  153.  
  154. conect.close();
  155. st.close();
  156. }
  157. catch(Exception e){System.out.println("[SQLException:]Data Violation:ERROR."); e.printStackTrace();}
  158. }
  159. }
  160. }
  161. public static void main(String args[])
  162. {
  163. CarHistory CH = new CarHistory("<<<< AUTOMOBILE TRACKING SYSTEM >>>>>");
  164. CH.setSize(800,250);
  165. CH.setVisible(true);
  166. CH.setResizable(false);
  167. CH.setLocation(200,100);
  168. }
  169. }
Last edited by Narue; Nov 12th, 2007 at 4:14 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Needs Brainstorming!!!

 
0
  #3
Nov 12th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: princestasnley is an unknown quantity at this point 
Solved Threads: 0
princestasnley princestasnley is offline Offline
Newbie Poster

Re: Needs Brainstorming!!!

 
0
  #4
Nov 12th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC