Exercises for the course Databases and Information Systems I WS 2006/2007 Special exercise JDBC

Ähnliche Dokumente
Grundlagen von Datenbanken SS 2010 Kapitel 8: Datenbank-Einbettung in Programmiersprachen Prof. Dr. Stefan Böttcher Universität Paderborn

Webbasierte Informationssysteme

Java-Datenbankzugriff mit JDBC

JDBC. Es kann z.b. eine ODBC-Treiberverbindung eingerichtet werden, damit das JAVA-Programm auf eine ACCESS-DB zugreifen kann.

Kapitel 10. JDBC und SQLJ. Prof. Dr. Wolfgang Weber Vorlesung Datenbanken 1

Java Database Connectivity (JDBC) Walther Rathenau Gewerbeschule 1

Wie kommen die Befehle zum DBMS

DB-Programmierung. Lehr- und Forschungseinheit Datenbanken und Informationssysteme 1. Ziele. DB2 Zugriff mit Java selbst programmieren

Einführung in JDBC. IFIS Universität zu Lübeck

Vorlesung Informatik II

p^db=`oj===pìééçêíáåñçêã~íáçå=

Programmieren II. Beispiele für RDBMS. Relationale Datenbanken. Datenbanken SQL. Dr. Klaus Höppner JDBC. Hochschule Darmstadt SS 2008

How-To-Do. Communication to Siemens OPC Server via Ethernet

Udo Matthias Munz. Datenbanken und SQL. mit. Einführung. Informationstechnik

Exercise (Part II) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

seit Java 1.1 Bestandteil der API: packages java.sql, javax.sql

Oracle: Abstrakte Datentypen:

Java Application 1 Java Application 2. JDBC DriverManager. JDBC-ODBC Br idge. ODBC Driver Manager. Dr iver C. Dr iver D.

Transaktionen in der Praxis. Dr. Karsten Tolle

Beispiel: DB-Mock (1/7)

p^db=`oj===pìééçêíáåñçêã~íáçå=

VGM. VGM information. HAMBURG SÜD VGM WEB PORTAL - USER GUIDE June 2016

Programmentwicklung ohne BlueJ

1. General information Login Home Current applications... 3

6. Übung - Datenbankprogrammierung

Exercise (Part XI) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Isolationsstufen für. Dr. Karsten Tolle Dienstag 31. Januar 2012

vs. Fehler zur Übersetzungszeit

Client/Server-Programmierung

MySQL mit MyLinux. 2/2003 Java unter Linux

How-To-Do. Hardware Configuration of the CC03 via SIMATIC Manager from Siemens

Java und Datenbanksysteme Datenbankanbindung mit JDBC

Der Adapter Z250I / Z270I lässt sich auf folgenden Betriebssystemen installieren:

Modifikation der Datenbank

Datenbankanwendungen (JDBC)

Wählen Sie das MySQL Symbol und erstellen Sie eine Datenbank und einen dazugehörigen User.

Microsoft Azure Fundamentals MOC 10979

How to access licensed products from providers who are already operating productively in. General Information Shibboleth login...

Quick Installation Guide for 4 and 7-Port Broadband Router

Exercise (Part I) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Hauptschritte einer JDBC-App

NVR Mobile Viewer for iphone/ipad/ipod Touch

Wie kommen die Befehle zum DBMS

Exercise (Part VIII) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Installationshinweise Z501J / Z501K Adapter IrDa USB Installation hints Z501J / Z501K Adapter IrDa USB

Whitepaper. Produkt: combit Relationship Manager. Datensatzhistorie mit dem SQL Server 2000 und combit GmbH Untere Laube Konstanz

Ingenics Project Portal

Tag 5 Inhaltsverzeichnis

NEWSLETTER. FileDirector Version 2.5 Novelties. Filing system designer. Filing system in WinClient

Datenbanken & Informationssysteme Übungen Teil 1

Tag 5 Inhaltsverzeichnis

embedded SQL Embedded SQL wurde erstmals im SQL92- Standard definiert.

11 Anwendungsprogrammierung

3. Datenbankzugriff (JDBC) Grundlagen der Programmierung II (Java)

How-To-Do. Hardware Configuration of the CPU 317NET with external CPs on the SPEED Bus by SIMATIC Manager from Siemens

MySQL-Befehle. In diesem Tutorial möchte ich eine kurze Übersicht der wichtigsten Befehle von MySQL geben.

Datenbanken 1 für Mediennformatiker WS ODBC, JDBC und SQLJ: Datenbank-Anbindung an Anwendungsprogramme

UNIVERSITÄT ULM Fakultät für Ingenieurswissenschaften und Informatik Institut für Datenbanken und Informationssysteme

USB Treiber updaten unter Windows 7/Vista

Prof. Dr.-Ing. Wolfgang Lehner. Externe User Defined Functions und externe Stored Procedures

Zugriff auf die Datenbank. Ulf Leser Wissensmanagement in der Bioinformatik

PROGRAMMIERPROJEKT 2016 VERWENDETE TECHNOLOGIEN

Analyse und praktischer Vergleich von neuen Access- Layer-Technologien in modernen Webanwendungen unter Java. Oliver Kalz

Readme-USB DIGSI V 4.82

Cameraserver mini. commissioning. Ihre Vision ist unsere Aufgabe

7. Datenbank-Zugriff. Vorlesung und Übung Dr. Peter Pfahler Institut für Informatik Universität Paderborn. Zum Beispiel aus PHP-Skripten: Client 7-2

Meeting and TASK TOOL. Bedienungsanleitung / Manual IQxperts GmbH. Alle Rechte vorbehalten.

Installation MySQL Replikationsserver

Datenbanksysteme 2011

MATLAB driver for Spectrum boards

Load balancing Router with / mit DMZ

FIRMWARE UPDATE TAPMOTION TD

ReadMe zur Installation der BRICKware for Windows, Version ReadMe on Installing BRICKware for Windows, Version 6.1.2

Instruktionen Mozilla Thunderbird Seite 1

Datenbanksysteme I Datenbankprogrammierung Felix Naumann

ORM & OLAP. Object-oriented Enterprise Application Programming Model for In-Memory Databases. Sebastian Oergel

RailMaster New Version 7.00.p26.01 /

X83-Konverter Instructions

Microsoft Project Herausgeber BerCom Training GmbH Stationsstrasse Uerikon. Kontakte:

Kurzanleitung um Transponder mit einem scemtec TT Reader und der Software UniDemo zu lesen

JDBC. Allgemeines ODBC. java.sql. Beispiele

Datenbankzugriff mit JDBC

If you have any issue logging in, please Contact us Haben Sie Probleme bei der Anmeldung, kontaktieren Sie uns bitte 1

Session 1: Classes and Applets

Nachdem Sie die Datei (z.b. t330usbflashupdate.exe) heruntergeladen haben, führen Sie bitte einen Doppelklick mit der linken Maustaste darauf aus:

Die Datenmanipulationssprache SQL

Invitation - Benutzerhandbuch. User Manual. User Manual. I. Deutsch Produktübersicht Beschreibung... 2

NoSQL mit Postgres 15. Juni 2015

Object Relational Mapping Layer

6.9 Java Server Pages

Datenbanksysteme. Programmieren von Datenbankzugriffen mit JDBC. Burkhardt Renz. Fachbereich MNI Technische Hochschule Mittelhessen

Übung Datenbanksysteme I JDBC. Thorsten Papenbrock


ALL1681 Wireless g Powerline Router Quick Installation Guide

USB -> Seriell Adapterkabel Benutzerhandbuch

Vorbereitung auf die JDBC/SQLJ Datenbankübungen

Datenbanksysteme I. Klausur zum Praktikum. Mehrere Professoren prüfen mit genau einem Beisitzer genau einen Studenten.

SELF-STUDY DIARY (or Lerntagebuch) GER102

Transkript:

Prof. Dr. Stefan Böttcher Exercises for the course Databases and Information Systems I WS 2006/2007 Special exercise JDBC 1. Preliminary configurations 1.1. Register ODBC database Chose Arbeitsplatz Systemsteuerung Verwaltung Datenquellen(ODBC) and then the tab Benutzer-DSN. If the name "odbc2access" is not yet registered: Select the button "Hinzufügen, and then chose from the list of drivers the driver "Microsoft Access-Driver (*.mdb)". Click "Fertigstellen". Chose "odbc2access" as name of the data source. Click "Auswählen" in the panel Datenbanken and select the database db2000.mdb which is contained in the zip-file, Click OK repeatedly to leave the ODBC data source administrator. 1.2 Configure variables The batch file j5pool.bat configures the variables PATH and CLASSPATH. This batch file has to be executed in each DOS-shell. Open a DOS-shell, execute the batchfile and compile and execute the program dbinit.java: working directory > j5pool working directory > javac dbinit.java working directory > java dbinit 1.3 Overview of examples The program dbinit.java generates a small example database. It demonstrates how to create and to delete tables and how to insert entries in to the database. The program dbselect.java demonstrates how to execute queries on the database with JDBC and how to process the results in the java program. The programs dbinf.java and dbtab.java demonstrate how to access meta information of the database and of the database tables. The programs exinit.java, exselect.java, exselect.java, exinf.java and extab.java demonstrate the same issues on an excel spreadsheet instead of an access database. The program excel2db.java shows the conversion of an excel spreadsheet into an access table and vice versa. 2. Exercises 2.1. Creating a database and executing queries E1.1. Compile and execute dbinit.java and dbselect.java to initialize and query the database Page 1 of 7

E1.2. Add two stmt.executeupdate commands in dbinit.java to insert the following information: "Dell supplies a pc400, price: 1800, duration: 2 days" and "Reich orders a pc500 ". Compile and execute dbinit.java once again and then execute dbselect.java to verify the modifications. E1.3. Add the query: Who supplies (at least) one item that has been ordered by Reich to the program dbselect.java and output the results via JDBC. Modify if necessary the database to verify the correctness of your modifications. 2.2. Querying meta data E2: Implement a program that outputs the complete content of all tables of the database. (Hint: Combine dbinf.java and dbtab.java) 2.3. Searching for Strings in the whole database E3: Implement a program that searches for a given String (e.g. pc400 ) in the whole database, i.e., that outputs each tuple of the database that contains the given String, no matter in which table or in which table-column this string is contained. Page 2 of 7

3. Examples 3.1. Initializing a database: source code dbinit.java public class dbinit try ergebnis = makedb( con ) ; // darf nicht von einer Exception aus makedb übersprungen werden! catch (Exception e) System.out.println( e ) ; public static String makedb( Connection con ) try Statement stmt = con.createstatement() ; try "drop table Liefert" ); catch (Exception e) "create table Liefert( Lieferant char(10), Teil char(10), " + " Preis int, Lieferzeit int ) " ); "Insert into Liefert values('vobis ','pc400',1700,3)" ); "Insert into Liefert values('dell ','pc500',2000,6)" ); "Insert into Liefert values('ibm ','pc500',2500,6)" ); "Insert into Liefert values('vobis ','pc500',2000,3)" ); "Insert into Liefert values('ibm ','pc600',3500,4)" ); "Insert into Liefert values('vobis ','pc600',2500,3)" ); Page 3 of 7

try "drop table Auftrag" ); catch (Exception e) "create table Auftrag( Kunde char(10), PC char(10) ) " ); "Insert into Auftrag values('arm ','pc400') " ); "Insert into Auftrag values('meier','pc500') " ); "Insert into Auftrag values('reich','pc600') " ); stmt.close(); // Statement schließen ausgabe += "\ndatenbank initialisiert.\n" ; catch (Exception e) ausgabe += "\n" + "Fehler: " + e ; return ausgabe ; // makedb zuende // class zuende 3.2. Selecting data: source code dbselect.java public class dbselect try ergebnis = selecttab( con, "2200" ) ; catch (Exception e) System.out.println( e ) ; public static String selecttab( Connection con, String limit ) try Statement stmt = con.createstatement() ; ResultSet rsliefert = stmt.executequery( "SELECT * FROM Liefert WHERE Preis < " + limit ) ; Page 4 of 7 // Strings in SQL müßten zusätzlich in einfache Hochkommas:

// "SELECT * FROM Liefert WHERE Teil = '" + limit + "'" ) ; ausgabe += "\n\nliefert:\n( Lieferant Teil" + " Preis Lieferzeit )" ; while (rsliefert.next()) // hole nächstes Tupel aus Result-Set ausgabe += "\n" + rsliefert.getstring("lieferant") + " " + rsliefert.getstring("teil") + " " + rsliefert.getint("preis") + " " + rsliefert.getint("lieferzeit") ; rsliefert.close() ; // Result-Set schließen stmt.close() ; // Statement schließen catch (Exception e) ausgabe += "\nfehler bei Anfrage an die Datenbank:\n" + e ; return ausgabe ; // selecttab zuende // class zuende Page 5 of 7

3.3. Querying database meta data: source code dbinf.java public class dbinf try ergebnis = accessdb( con ) ; catch (Exception e) System.out.println( e ) ; public static String accessdb( Connection con ) try DatabaseMetaData md = con.getmetadata(); // Metadaten holen // Hilfsvariable final String[] tabellen = "TABLE"; // Hole Tabellennamen ResultSet tablesnames =md.gettables(null,null,null,tabellen); while (tablesnames.next()) // Hole Tabellenname String tablename = new String(tablesNames.getString(3)); ausgabe += tablename + "\n" ; catch (Exception e) ausgabe += e ; return ausgabe; // accessdb // dbinf Page 6 of 7

3.4. Querying table meta data: source code dbtab.java public class dbtab try ergebnis = accesstab( con, "Auftrag" ) ; catch (Exception e) System.out.println( e ) ; public static String accesstab( Connection con, String tabelle ) int spalte; try Statement stmt = con.createstatement(); // Statement anlegen ResultSet rs = stmt.executequery("select * from " + tabelle); // Hole Meta-Daten für dieses Result Set ResultSetMetaData rsmd= rs.getmetadata(); int spaltenanzahl = rsmd.getcolumncount(); for( spalte=1 ; spalte <= spaltenanzahl ; spalte++ ) ausgabe += rsmd.getcolumnlabel( spalte ) + "\t\t" ; ausgabe += "\n-------------------------------------\n" ; while (rs.next()) for( spalte=1 ; spalte <= spaltenanzahl ; spalte++ ) ausgabe += rs.getstring(spalte) + "\t" ; ausgabe += "\n" ; catch (Exception e) ausgabe += e ; return ausgabe; // accesstab // dbtab Page 7 of 7