By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,101 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,101 IT Pros & Developers. It's quick & easy.

Urgent Help Needed for program due on Fri. Dec. 8th in the afternoon!

P: 2
below is my almost completed code. I need help trying to figure out how to display to a textarea all the data I have in phpMyAdmin (database). I have two methods near the bottom called itemResults() and productResults() with the body of them commented out so it will compile. What is commented out is the way I think it should work but it is not working. If anyone would like to see entire code I would be glad to email for it will not let me post all of it. I have it on the web if you would like to see it working and have better idea of what I need: http://web6.duc.auburn.edu/~halljab/...runapplet.html Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1.  
  2. public void loadDatabase()
  3. {
  4.  
  5. try
  6. {
  7.  
  8. //Load MySQL drivers
  9. Class.forName("org.gjt.mm.mysql.Driver");
  10.  
  11. }
  12.  
  13. catch( java.lang.ClassNotFoundException e )
  14. {
  15.  
  16. showStatus("MySQL ORG Package Driver not found ...");
  17. System.err.println(e.getMessage());
  18.  
  19. }
  20.  
  21. try
  22. {
  23.  
  24. //Connect to the database
  25. conBrads_mySQL = DriverManager.getConnection(dbURL);
  26.  
  27. }
  28.  
  29. catch(SQLException error)
  30. {
  31.  
  32. System.err.println("Unable to Connect to Database");
  33.  
  34. }
  35.  
  36. try
  37. {
  38.  
  39. Statement cmdBrads_mySQL = conBrads_mySQL.createStatement();
  40.  
  41. //Create the ResultSet
  42. rsBrads_mySQL = cmdBrads_mySQL.executeQuery("Select * from Brads_mySQL.Items;");
  43. loadItemName(rsBrads_mySQL);
  44.  
  45. rsBrads_mySQL = cmdBrads_mySQL.executeQuery("Select * from Brads_mySQL.Products;");
  46. loadProductName(rsBrads_mySQL);
  47.  
  48. blnSuccessfulOpen = true;
  49.  
  50. }
  51.  
  52. catch(SQLException error)
  53. {
  54.  
  55. System.err.println("Error in recordset");
  56.  
  57. }
  58. }
  59.  
  60. public void loadItemName(ResultSet rsBrads_mySQL)
  61. {
  62.  
  63. //Fill item list box
  64. try
  65. {
  66.  
  67. while(rsBrads_mySQL.next())
  68. {
  69.  
  70. lstItems.add(rsBrads_mySQL.getString("ItemName"));
  71.  
  72. }
  73. }
  74.  
  75. catch (SQLException error)
  76. {
  77.  
  78. System.err.println("Error in Display Record");
  79.  
  80. }
  81. }
  82.  
  83. public void loadProductName(ResultSet rsBrads_mySQL)
  84. {
  85.  
  86. //Fill product list box
  87. try
  88. {
  89.  
  90. while(rsBrads_mySQL.next())
  91. {
  92.  
  93. lstProducts.add(rsBrads_mySQL.getString("ProductName"));
  94.  
  95. }
  96. }
  97.  
  98. catch (SQLException error)
  99. {
  100.  
  101. System.err.println("Error in Display Record");
  102.  
  103. }
  104. }
  105.  
  106. public void actionPerformed (ActionEvent event)
  107. {
  108.  
  109. Object objSource = event.getSource();
  110.  
  111. if (objSource == btnAddItem && event.getActionCommand() == "Add")
  112. addItems();
  113. else if (objSource == btnAdd && event.getActionCommand() == "Add")
  114. addProducts();
  115. else if (objSource == btnAddItem)
  116. saveItems();
  117. else if(objSource == btnEditItem)
  118. editItems();
  119. else if(objSource == btnDeleteItem)
  120. deleteItems();
  121. else if(objSource == btnCancelItem)
  122. cancelItems();
  123. else if (objSource == btnAdd)
  124. saveProducts();
  125. else if(objSource == btnEdit)
  126. editProducts();
  127. else if(objSource == btnDelete)
  128. deleteProducts();
  129. else if(objSource == btnCancel)
  130. cancelProducts();
  131. else if(objSource == btnFirstItem)
  132. firstItemRecord();
  133. else if(objSource == btnPreviousItem)
  134. previousItemRecord();
  135. else if(objSource == btnNextItem)
  136. nextItemRecord();
  137. else if(objSource == btnLastItem)
  138. lastItemRecord();
  139. else if(objSource == btnFirst)
  140. firstProductRecord();
  141. else if(objSource == btnPrevious)
  142. previousProductRecord();
  143. else if(objSource == btnNext)
  144. nextProductRecord();
  145. else if(objSource == btnLast)
  146. lastProductRecord();
  147. else if(objSource == btnItemDisplay)
  148. itemResults();
  149. else if(objSource == btnProductDisplay)
  150. productResults();
  151.  
  152. }
  153.  
  154. public void itemStateChanged(ItemEvent event)
  155. {
  156.  
  157. String strItemName = lstItems.getSelectedItem();
  158. String strProductName = lstProducts.getSelectedItem();
  159.  
  160. showStatus("");
  161.  
  162. Object objSource = event.getSource();
  163.  
  164. if (objSource == lstItems)
  165. {
  166.  
  167. try
  168. {
  169.  
  170. Statement cmdBrads_mySQL = conBrads_mySQL.createStatement();
  171. rsBrads_mySQL = cmdBrads_mySQL.executeQuery(
  172. "Select * from Brads_mySQL.Items where ItemName = '" + strItemName + "';");
  173. txtItemName.setText(strItemName);
  174. displayItemRecord(rsBrads_mySQL);
  175. itemAlteredState();
  176.  
  177. }
  178.  
  179. catch(SQLException error)
  180. {
  181.  
  182. showStatus("Error in recordset");
  183.  
  184. }
  185. }
  186.  
  187. else if (objSource == lstProducts)
  188. {
  189.  
  190. try
  191. {
  192.  
  193. Statement cmdBrads_mySQL = conBrads_mySQL.createStatement();
  194. rsBrads_mySQL = cmdBrads_mySQL.executeQuery(
  195. "Select * from Brads_mySQL.Products where ProductName = '" + strProductName + "';");
  196. txtProductName.setText(strProductName);
  197. displayProductRecord(rsBrads_mySQL);
  198. productAlteredState();
  199.  
  200. }
  201.  
  202. catch(SQLException error)
  203. {
  204.  
  205. showStatus("Error in recordset");
  206.  
  207. }
  208. }
  209. }
  210.  
  211. public void displayItemRecord(ResultSet rsBrads_mySQL)
  212. {
  213.  
  214. //Display the current record
  215. try
  216. {
  217.  
  218. if(rsBrads_mySQL.next())
  219. {
  220.  
  221. txtItems.setText(rsBrads_mySQL.getString("ItemID"));
  222. txtItemName.setText(rsBrads_mySQL.getString("ItemName"));
  223. txtItemQuantity.setText(rsBrads_mySQL.getString("ItemQuantity"));
  224. txtItemDescription.setText(rsBrads_mySQL.getString("ItemDescription"));
  225. showStatus("");
  226.  
  227. }
  228.  
  229. else
  230. {
  231.  
  232. showStatus("Record not found");
  233. clearItemTextFields();
  234.  
  235. }
  236. }
  237.  
  238. catch (SQLException error)
  239. {
  240.  
  241. showStatus("Error in display record");
  242.  
  243. }
  244. }
  245.  
  246. public void displayProductRecord(ResultSet rsBrads_mySQL)
  247. {
  248.  
  249. //Display the current record
  250. try
  251. {
  252.  
  253. if(rsBrads_mySQL.next())
  254. {
  255.  
  256. txtProduct.setText(rsBrads_mySQL.getString("ProductID"));
  257. txtProductName.setText(rsBrads_mySQL.getString("ProductName"));
  258. txtProductQuantity.setText(rsBrads_mySQL.getString("ProductQuantity"));
  259. txtProductDescription.setText(rsBrads_mySQL.getString("ProductDescription"));
  260. showStatus("");
  261.  
  262. }
  263.  
  264. else
  265. {
  266.  
  267. showStatus("Record not found");
  268. clearProductTextFields();
  269.  
  270. }
  271. }
  272.  
  273. catch (SQLException error)
  274. {
  275.  
  276. showStatus("Error in display record");
  277.  
  278. }
  279. }
  280.  
  281. public void itemResults()
  282. {
  283.  
  284. //Display the Report
  285. //try
  286. //{
  287.  
  288. //if(rsBrads_mySQL.next())
  289. //{
  290.  
  291. //txaItemReport.append("" + txtItems.setText(rsBrads_mySQL.getString("ItemID"))
  292. //+ "\n" + txtItemName.setText(rsBrads_mySQL.getString("ItemName")) + "\n" +
  293. //txtItemQuantity.setText(rsBrads_mySQL.getString("ItemQuantity")) + "\n" +
  294. //txtItemDescription.setText(rsBrads_mySQL.getString("ItemDescription")) + "\n\n\n");
  295. //showStatus("Report Complete");
  296.  
  297. //}
  298.  
  299. //else
  300. //{
  301.  
  302. //showStatus("Record not found");
  303.  
  304. //}
  305. //}
  306.  
  307. //catch (SQLException error)
  308. //{
  309.  
  310. //showStatus("Error trying to Report");
  311.  
  312. //}
  313. }
  314.  
  315. public void productResults()
  316. {
  317.  
  318. //Display the Report
  319. //try
  320. //{
  321.  
  322. //if(rsBrads_mySQL.next())
  323. //{
  324.  
  325. //txaProductReport.append("" + txtProduct.setText(rsBrads_mySQL.getString("ItemID"))
  326. //+ "\t" + txtProductName.setText(rsBrads_mySQL.getString("ItemName")) + "\t" +
  327. //txtProductQuantity.setText(rsBrads_mySQL.getString("ItemQuantity")) + "\t" +
  328. //txtProductDescription.setText(rsBrads_mySQL.getString("ItemDescription")) + "\n\n");
  329. //showStatus("Report Complete");
  330.  
  331. //}
  332.  
  333. //else
  334. //{
  335.  
  336. //showStatus("Record not found");
  337.  
  338. //}
  339. //}
  340.  
  341. //catch (SQLException error)
  342. //{
  343.  
  344. //showStatus("Error trying to Report");
  345.  
  346. //}
  347. }
  348.  
Dec 6 '06 #1
Share this Question
Share on Google+
3 Replies


Expert Mod 100+
P: 2,327
Using the CODE tags would have been nice.
Made the changes for you.
Dec 7 '06 #2

10K+
P: 13,264
Using the CODE tags would have been nice.
Made the changes for you.
We do not have your database so testing this might be a bit difficult. So why don't you specify what errors you are getting when compiling.
Dec 7 '06 #3

P: 2
Coded as it is now with the itemReport() commented out it compiles because the method is not used but the following is the error I am getting if I uncomment it (same with productReport()):

Expand|Select|Wrap|Line Numbers
  1. "Inventory.java": 'void' type not allowed here at line 1030, column 30
  2. "Inventory.java": 'void' type not allowed here at line 1031, column 9
  3. "Inventory.java": 'void' type not allowed here at line 1031, column 75
  4. "Inventory.java": 'void' type not allowed here at line 1032, column 74
Dec 7 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.