Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication3;
- //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:
- //Huidige klant:
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Scanner;
- // Some translations :
- //Eerste = first
- //Vorige = previous
- //Volgende = next
- //Laatste = last
- //1 - Alex Vervoort – Grootstraat 1 – 3500 Hasselt – 1/1/1991
- //Navigatiemenu:
- //1. Eerste
- //2. Vorige
- //3. Volgende
- //4. Laatste
- //5. Einde
- //Maak uw keuze: 3
- //Huidige klant:
- //2 - Dieter Droogmans – Kleine Laan 2 – 3500 Hasselt – 5/5/1999
- //Navigatiemenu:
- //1. Eerste
- //2. Vorige
- //3. Volgende
- //4. Laatste
- //5. Einde
- //Maak uw keuze: 5
- //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 ...
- //Gebruik ook de try catch (ParseException e) .
- /**
- *
- * @author 6 TSO Informatica 1
- */
- public class JavaApplication3 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- try {
- Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
- String select = "Select * from Klanten ";
- rs = s.executeQuery(select);
- System.out.println("De klanten zijn:");
- rs.first();
- System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
- ShowMenu();
- con.close();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- System.exit(0);
- }
- }
- private static Connection getConnection() {
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- String url = "jdbc:odbc:DVDVerhuur";
- con = DriverManager.getConnection(url);
- con.setAutoCommit(true);
- } catch (ClassNotFoundException e) {
- System.out.println(e.getMessage());
- System.exit(0);
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- System.exit(0);
- }
- return con;
- }
- private static void ShowMenu() {
- //Navigatiemenu:
- //1. Eerste
- //2. Vorige
- //3. Volgende
- //4. Laatste
- //5. Einde
- //Maak uw keuze:
- System.out.println("Navigatiemenu:");
- System.out.println("1. Eerste");
- System.out.println("2. Vorige");
- System.out.println("3. Volgende");
- System.out.println("4. Laatste");
- System.out.println("5. Einde");
- System.out.print("Maak uw keuze:");
- String invoer = new Scanner(System.in).nextLine();
- int keuze = Integer.parseInt(invoer);
- if (keuze == 1) {
- Eerste();
- } else if (keuze == 2) {
- Vorige();
- } else if (keuze == 3) {
- Volgende();
- } else if (keuze == 4) {
- Laatste();
- } else if (keuze == 5) {
- }
- }
- private static void Eerste() {
- try {
- System.out.println("De klanten zijn:");
- rs.first();
- System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
- ShowMenu();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- System.exit(0);
- }
- }
- static ResultSet rs;
- static Connection con = getConnection();
- private static void Vorige() {
- try {
- System.out.println("De klanten zijn:");
- rs.previous();
- System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
- ShowMenu();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- System.exit(0);
- }
- }
- private static void Volgende() {
- try {
- System.out.println("De klanten zijn:");
- if (!rs.relative(1)) {
- rs.first();
- }
- System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
- ShowMenu();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- System.exit(0);
- }
- }
- private static void Laatste() {
- try {
- System.out.println("De klanten zijn:");
- rs.last();
- System.out.println("Naam en voornaam: " + rs.getString("KlantVoornaam") + " " + rs.getString("KlantNaam"));
- ShowMenu();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement