Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class einlesen {
- static Statement sql_stmt = null;
- static Connection conn = null;
- public static void main(String[]args){
- loadmenue();
- }
- public static void loadmenue(){
- System.out.println(" ");
- System.out.println("++++Menue+++++");
- System.out.println("anzeigen");
- System.out.println("einfuegen");
- System.out.println("loeschen");
- System.out.println("beenden");
- System.out.println(" ");
- Eingabe tastatur = Eingabe.oeffnen("");
- String s = tastatur.readString();
- if(s.equals("anzeigen"))
- {
- anzeigen();
- }
- else if(s.equals("einfuegen")){
- System.out.println("Albumtitel");
- String a = tastatur.readString();
- System.out.println("Interpret");
- String i = tastatur.readString();
- System.out.println("Erscheinungsjahr");
- int abc = tastatur.readint();
- einfuegen(a,i,abc);
- }
- else if(s.equals("loeschen")){
- String loe = tastatur.readString();
- loeschen(loe);
- }else if(s.equals("beenden")){
- System.exit(-1);
- }else{System.out.println("unkown command");
- loadmenue();
- }
- }
- public static void anzeigen(){
- Statement sql_stmt = null;
- Connection conn = null;
- try {
- Class.forName("org.hsqldb.jdbcDriver");
- conn = DriverManager.getConnection
- ("jdbc:hsqldb:hsql://localhost/", "sa", "");
- sql_stmt = conn.createStatement();
- }
- catch (Exception e) {
- System.err.println("Folgender Fehler ist aufgetreten: " + e);
- System.exit(-1); }
- try {
- ResultSet rset = sql_stmt.executeQuery(
- "select Albumtitel,Interpret from Album");
- System.out.println("Alben:");
- while(rset.next()) {
- System.out.println(rset.getString("Albumtitel") + " von: " +
- rset.getString("Interpret"));
- }
- rset.close();
- loadmenue();
- }
- catch(SQLException se) {System.out.println("Error: " + se); }
- try {
- sql_stmt.close(); conn.close();
- }
- catch (SQLException e) {
- System.out.println("Fehler beim Schliessen der DB: " + e);
- }
- }
- public static void einfuegen(String t, String i, int j){
- Statement sql_stmt = null;
- Connection conn = null;
- try {
- Class.forName("org.hsqldb.jdbcDriver");
- conn = DriverManager.getConnection
- ("jdbc:hsqldb:hsql://localhost/", "sa", "");
- sql_stmt = conn.createStatement();
- }
- catch (Exception e) {
- System.err.println("Folgender Fehler ist aufgetreten: " + e);
- System.exit(-1); }
- try {
- String sqlQuery = null;
- Statement stmt = conn.createStatement();
- sqlQuery = ("INSERT INTO Album (Albumtitel, Interpret, Erscheinungsjahr) Values('"+t+"', '"+i+"', "+j+")");
- stmt.executeUpdate(sqlQuery);
- loadmenue();
- }
- catch(SQLException se) {System.out.println("Error: " + se); }
- try {
- sql_stmt.close(); conn.close();
- }
- catch (SQLException e) {
- System.out.println("Fehler beim Schliessen der DB: " + e);
- }
- }
- public static void loeschen(String loe){
- Statement sql_stmt = null;
- Connection conn = null;
- try {
- Class.forName("org.hsqldb.jdbcDriver");
- conn = DriverManager.getConnection
- ("jdbc:hsqldb:hsql://localhost/", "sa", "");
- sql_stmt = conn.createStatement();
- }
- catch (Exception e) {
- System.err.println("Folgender Fehler ist aufgetreten: " + e);
- System.exit(-1); }
- try {
- String sqlQuery = null;
- Statement stmt = conn.createStatement();
- sqlQuery = ("DELETE FROM Album WHERE Albumtitel='"+loe+"'");
- stmt.executeUpdate(sqlQuery);
- loadmenue();
- }
- catch(SQLException se) {System.out.println("Error: " + se); }
- try {
- sql_stmt.close(); conn.close();
- }
- catch (SQLException e) {
- System.out.println("Fehler beim Schliessen der DB: " + e);
- }
- }
- }
Add Comment
Please, Sign In to add comment