Here's a method i wrote to find an item in a MySQL database and to show the found item. I wrote this class for someone so the text might be confusing =) details of this application + screenshot can be found here: http://www.engineeringserver.com/blog/2007/12/28/tenant-application/

JAVA:
  1. public void findItemFromDatabase(){
  2. boolean add = true;
  3. int duplicate = 0;
  4. try {
  5. Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  6. Connection conn = DriverManager.getConnection (url, userName, password);
  7. Statement checkTenants = conn.createStatement();
  8. String queryCheckTenants = "select name from tenant";
  9. ResultSet resultCheck = checkTenants.executeQuery(queryCheckTenants);
  10. String find = findTf.getText();
  11. while(resultCheck.next()){
  12. if(resultCheck.getString("Name").equals(find)){
  13. duplicate++;
  14. }
  15. }
  16. if(duplicate>0){
  17. resultBtn.setVisible(true);
  18. resultFoundLbl.setText("Tendant found," + "\n" + "click detail(s) for more info.");
  19. resultFoundLbl.setVisible(true);
  20. searchBtn.setEnabled(false);
  21. findTf.setEditable(false);
  22. found = true;
  23. add = false;
  24. }
  25. else{
  26. resultBtn.setVisible(true);
  27. resultBtn.setEnabled(true);
  28. resultBtn.setText("Add tenant");
  29. resultFoundLbl.setText("No match found, " +"\n" + "please try again or add new tenant.");
  30. resultFoundLbl.setVisible(true);
  31. searchBtn.setEnabled(false);
  32. findTf.setEditable(false);
  33. found = false;
  34. add = true;
  35. }
  36. //obsolette
  37. if (add){
  38. }
  39. if (!add){
  40. }
  41. e.printStackTrace();
  42. e.printStackTrace();
  43. e.printStackTrace();
  44. } catch (SQLException e) {
  45. e.printStackTrace();
  46. }
  47. }

Tags Tags: ,
Categories: Java
Posted By: HappyFace
Last Edit: 24 Aug 2008 @ 06 29 PM

E-mailPermalinkComments (0)
 04 Apr 2008 @ 8:24 PM 

This tutorial explains how to connect to a MySQL database using Java. I've wrote this tutorial for someone else but I don't have a direct link to his/her site so i'll temporarily blogpost it here until I have a link to the tutorial.

By: Ark – http://www.engineeringserver.com
Date: April/04/2008
Tutorial: MySQL with Java
Version: 1.0

Hi all, thanks for reading my "MySQL with Java" tutorial.
Before we start the tutorial you need to have I assume you know a little
bit about java like what Java classes are and how to create methods etc, if not, let me
know and i'll explain that another time.

Download / read the tutorial here:
http://www.freefilehost.co.uk/529158
password: engineeringserver.com

1 - MySqlWithJavaTutorial.pdf

More tutorials are currently being written, if you have a suggestion or a comment about this tutorial let me know!

Tags Tags: , ,
Categories: Java
Posted By: HappyFace
Last Edit: 12 May 2008 @ 10 26 PM

E-mailPermalinkComments (0)
\/ More Options ...
Change Theme...
  • Role »
  • Posts »
  • Comments »
Change Theme...
  • VoidVoid (Default)
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLightweight