Advertisement
Guest User

Untitled

a guest
May 26th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package javaapplication3;
  6. //Schrijf een console applicatie met een eenvoudig menu-systeem, waarin je navigeert door de klanten. Je geeft de id, de naam en voornaam van de huidige klant weer. Wanneer je bij de laatste klant voor “Volgende klant” kiest, dan kom je terug bij de eerste klant terecht. Bvb:
  7. //Huidige klant:
  8.  
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.util.Scanner;
  15. // Some translations :
  16. //Eerste = first
  17. //Vorige = previous
  18. //Volgende = next
  19. //Laatste = last
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. //1 - Alex Vervoort – Grootstraat 1 – 3500 Hasselt – 1/1/1991
  28. //Navigatiemenu:
  29. //1. Eerste
  30. //2. Vorige
  31. //3. Volgende
  32. //4. Laatste
  33. //5. Einde
  34. //Maak uw keuze: 3
  35. //Huidige klant:
  36. //2 - Dieter Droogmans – Kleine Laan 2 – 3500 Hasselt – 5/5/1999
  37. //Navigatiemenu:
  38. //1. Eerste
  39. //2. Vorige
  40. //3. Volgende
  41. //4. Laatste
  42. //5. Einde
  43. //Maak uw keuze: 5
  44. //Hoe een datum in bepaalde formaat weergeven? Volgende code heb je nodig: import java.text.*; import java.util.*; ... code ... java.util.Date mijnDatum; SimpleDateFormat formatter; mijnDatum = rs.getDate("KlantGeboorteDatum"); formatter = new SimpleDateFormat("dd/MM/yyyy"); if (mijnDatum != null) System.out.println(formatter.format(mijnDatum)); ... code ...
  45. //Gebruik ook de try catch (ParseException e) .
  46. /**
  47. *
  48. * @author 6 TSO Informatica 1
  49. */
  50. public class JavaApplication3 {
  51.  
  52. /**
  53. * @param args the command line arguments
  54. */
  55. public static void main(String[] args) {
  56. // TODO code application logic here
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. try {
  64. Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
  65. String select = "Select * from Klanten ";
  66. rs = s.executeQuery(select);
  67. System.out.println("De klanten zijn:");
  68. rs.first();
  69. System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
  70. ShowMenu();
  71.  
  72. con.close();
  73. } catch (SQLException e) {
  74. System.out.println(e.getMessage());
  75. System.exit(0);
  76. }
  77. }
  78.  
  79. private static Connection getConnection() {
  80. Connection con = null;
  81. try {
  82. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  83. String url = "jdbc:odbc:DVDVerhuur";
  84. con = DriverManager.getConnection(url);
  85. con.setAutoCommit(true);
  86. } catch (ClassNotFoundException e) {
  87. System.out.println(e.getMessage());
  88. System.exit(0);
  89. } catch (SQLException e) {
  90. System.out.println(e.getMessage());
  91. System.exit(0);
  92. }
  93. return con;
  94. }
  95.  
  96. private static void ShowMenu() {
  97. //Navigatiemenu:
  98. //1. Eerste
  99. //2. Vorige
  100. //3. Volgende
  101. //4. Laatste
  102. //5. Einde
  103. //Maak uw keuze:
  104. System.out.println("Navigatiemenu:");
  105. System.out.println("1. Eerste");
  106. System.out.println("2. Vorige");
  107. System.out.println("3. Volgende");
  108. System.out.println("4. Laatste");
  109. System.out.println("5. Einde");
  110. System.out.print("Maak uw keuze:");
  111. String invoer = new Scanner(System.in).nextLine();
  112. int keuze = Integer.parseInt(invoer);
  113. if (keuze == 1) {
  114. Eerste();
  115. } else if (keuze == 2) {
  116. Vorige();
  117. } else if (keuze == 3) {
  118. Volgende();
  119. } else if (keuze == 4) {
  120. Laatste();
  121. } else if (keuze == 5) {
  122. }
  123.  
  124. }
  125.  
  126. private static void Eerste() {
  127.  
  128. try {
  129.  
  130. System.out.println("De klanten zijn:");
  131. rs.first();
  132. System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
  133. ShowMenu();
  134.  
  135.  
  136. } catch (SQLException e) {
  137. System.out.println(e.getMessage());
  138. System.exit(0);
  139. }
  140. }
  141. static ResultSet rs;
  142. static Connection con = getConnection();
  143.  
  144. private static void Vorige() {
  145.  
  146. try {
  147.  
  148. System.out.println("De klanten zijn:");
  149. rs.previous();
  150. System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
  151. ShowMenu();
  152.  
  153.  
  154. } catch (SQLException e) {
  155. System.out.println(e.getMessage());
  156. System.exit(0);
  157. }
  158. }
  159.  
  160. private static void Volgende() {
  161.  
  162. try {
  163.  
  164. System.out.println("De klanten zijn:");
  165. if (!rs.relative(1)) {
  166. rs.first();
  167. }
  168. System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
  169. ShowMenu();
  170.  
  171.  
  172. } catch (SQLException e) {
  173. System.out.println(e.getMessage());
  174. System.exit(0);
  175. }
  176. }
  177.  
  178. private static void Laatste() {
  179. try {
  180.  
  181. System.out.println("De klanten zijn:");
  182. rs.last();
  183. System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
  184. ShowMenu();
  185.  
  186.  
  187. } catch (SQLException e) {
  188. System.out.println(e.getMessage());
  189. System.exit(0);
  190. }
  191. }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement