import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//package iotool
//readByte
//readShort
//readInt
//readLong
//readFloat
//readDouble
//readString
//readChar
public class eingabe {
//read-Byte-Methode
public static byte readByte(String inText) {
byte bZahl ;
BufferedReader br;
//Eingabepuffer für eine Dateneingabe neu erstellen
br = new BufferedReader(new InputStreamReader(System.in));
bZahl = 0;
System.out.print(inText);
try {
bZahl= Byte.parseByte(br.readLine());
}
catch (NumberFormatException e) {
System.out.println("Exception geworfen, kein Byte.");
}
catch (IOException e) {
e.printStackTrace();
}
return bZahl;
}
//read-Short-Methode
public static short readShort(String inText) {
short sZahl ;
BufferedReader br;
//Eingabepuffer für eine Dateneingabe neu erstellen
br = new BufferedReader(new InputStreamReader(System.in));
sZahl = 0;
System.out.print(inText);
try {
sZahl= Short.parseShort(br.readLine());
}
catch (NumberFormatException e) {
System.out.println("Exception geworfen, kein Short.");
}
catch (IOException e) {
e.printStackTrace();
}
return sZahl;
}
//read-Integer-Methode
public static int readInt(String inText) {
int iZahl ;
BufferedReader br;
//Eingabepuffer für eine Dateneingabe neu erstellen
br = new BufferedReader(new InputStreamReader(System.in));
iZahl = 0;
System.out.print(inText);
try {
iZahl= Integer.parseInt(br.readLine());
}
catch (NumberFormatException e) {
System.out.println("Exception geworfen, kein Integer.");
}
catch (IOException e) {
e.printStackTrace();
}
return iZahl;
}
//read-Long-Methode
public static long readLong(String inText) {
long lZahl ;
BufferedReader br;
//Eingabepuffer für eine Dateneingabe neu erstellen
br = new BufferedReader(new InputStreamReader(System.in));
lZahl = 0;
System.out.print(inText);
try {
lZahl= Long.parseLong(br.readLine());
}
catch (NumberFormatException e) {
System.out.println("Exception geworfen, kein Long.");
}
catch (IOException e) {
e.printStackTrace();
}
return lZahl;
}
//read-Float-Methode
public static float readFloat(String inText) {
float fZahl ;
BufferedReader br;
//Eingabepuffer für eine Dateneingabe neu erstellen
br = new BufferedReader(new InputStreamReader(System.in));
fZahl = 0;
System.out.print(inText);
try {
fZahl= Float.parseFloat(br.readLine());
}
catch (NumberFormatException e) {
System.out.println("Exception geworfen, kein float.");
}
catch (IOException e) {
e.printStackTrace();
}
return fZahl;
}
//read-Double-Methode
public static double readDouble(String inText) {
double dZahl ;
BufferedReader br;
//Eingabepuffer für eine Dateneingabe neu erstellen
br = new BufferedReader(new InputStreamReader(System.in));
dZahl = 0;
System.out.print(inText);
try {
dZahl= Double.parseDouble(br.readLine());
}
catch (NumberFormatException e) {
System.out.println("Exception geworfen, kein double.");
}
catch (IOException e) {
e.printStackTrace();
}
return dZahl;
}
//read-String-Methode
public static String readString(String inText) {
String sText ;
BufferedReader br;
//Eingabepuffer für eine Dateneingabe neu erstellen
br = new BufferedReader(new InputStreamReader(System.in));
sText = "";
System.out.print(inText);
try {
sText= (br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
return sText;
}
//read-Character-Methode
public static char readChar(String inText) {
char cZeichen ='0';
System.out.print(inText);
try {
do{
cZeichen =(char) System.in.read();
}
while(cZeichen == '\n' | cZeichen =='\r');
}
catch (IOException e) {
e.printStackTrace();
}
return cZeichen;
}
}
//found @ coderz-home.de, modified by ewing 20150131
#java
3262 (line, diamond)
play with lines/diamond in java (external input class)
class j1exam01
{
public static void printLine (int highest, int length)
{
int digit = 0;
int help = 0;
int spaces = (length - (2 * highest + 1)) / 2;
//print leading spaces
if (spaces > 0)
{
for (int i = 0; i < spaces; i++)
{
System.out.print (" ");
}
}
//print digits
switch (highest)
{
//case highest 0
case 0:
{
System.out.print ("0");
break;
}
//case highest 1
case 1:
{
System.out.print ("010");
break;
}
//case other
default:
{
for (int i = 0; i 0)
{
for (int i = 0; i < spaces; i++)
{
System.out.print (" ");
}
}
//print newline
System.out.println();
}
public static void printDiamond (int center)
{
int digit = 0;
int help = 0;
int length = (2 * center) + 1;
//print empty line
System.out.println();
//diamond
switch (center)
{
case 0:
{
printLine (0, 1);
break;
}
case 1:
{
printLine (0, 3);
printLine (1, 3);
printLine (0, 3);
break;
}
default:
{
for (int i = 0; i < ((2 * center) + 1); i++)
{
if (i center) { digit = center - help; help++; }
printLine (digit, length);
}
break;
}
}
//print newline {([done in printLine()])}
//print empty line
System.out.println();
}
public static void main (String[] args)
{
int q = 0;
int h, l, c;
h = 0;
l = 0;
c = 0;
//main menu
do
{
q = eingabe.readInt("(1)line, (2)diamond or (3)end?");
if (q == 1)
{
h = eingabe.readInt("highest:");
l = eingabe.readInt("length:");
printLine (h, l);
}
else if (q == 2)
{
c = eingabe.readInt("center:");
printDiamond (c);
}
} while (!(q == 3));
System.out.println ("this is the end");
}
}
3105 (array histogram special case max 3)
public class hist
{
public static int[] histogram (int [][] arrayA)
{ // nested for loop to go through the array.
int max = 0;
for ( int row = 0; row<arrayA.length; row++)
{
for ( int col=0; col < arrayA[row].length; col++)
{
if ( arrayA[row][col]> max )
{
max = arrayA[row][col];
}
}
}
System.out.println("max:"+max);
int histA[] = new int [max+1];
int lauf = 0;
for (lauf=0;lauf<max+1;lauf++)
{
for ( int row = 0; row<arrayA.length; row++)
{
for ( int col=0; col < arrayA[row].length; col++)
{
if (arrayA[row][col] == lauf)
{
histA[lauf]++;
}
//histA[arrayA[row][col]]++;
}
}
}
//System.out.println(histA);
return histA;
}
public static void main (String[]args)
{
// declearing and initializing a 2D array.
int [][] arrayA = {{0,1,2},{3,0,2},{3,3,0}};
int erg[]={};
erg = histogram(arrayA);
for (int i = 0; i<=3; i++)
{
System.out.println(i+":"+erg[i]);
}
}
}
3101 (some convertingtools)
4 javapieces int_to_bin/bin_to_int/int_to_hex/hex_to_int
int_to_bin
class dec_bin
{
public static String b0(int n) {
if (n == 0) return "0";
if (n == 1) return "1";
return b0(n / 2) + (n % 2);
}
public static void main (String[] args)
{
int ein=0;
String erg="";
ein=eingabe.readInt("Integer:");
erg= b0(ein);
System.out.println(erg);
}
}
bin_to_int
class bin_dec
{
public static void main (String[] args)
{
String ein = "";
int foo=0;
ein=eingabe.readString("String(bin):");
foo = Integer.parseInt(ein, 2);
System.out.println(foo);
}
}
int_to_hex
class dec_hex
{
public static String intToHexStr(int i){
return "0x"+String.format("%2s", Integer.toHexString(i)).replace(' ', '0');
}
public static void main (String[] args)
{
int ein=0;
String erg="";
ein=eingabe.readInt("Integer:");
erg=intToHexStr(ein);
System.out.println(erg);
}
}
hex_to_int
class hex_dec
{
public static void main (String[] args)
{
String ein = "";
String foo="";
String bar="";
int value=0;
ein=eingabe.readString("String(hex):");
foo=ein.substring(0,2);
if (foo.equals("0x")) { bar = ein.substring(2); }
else { bar = ein; }
value = Integer.parseInt(bar, 16);
System.out.println(value);
}
}
3097
drei 3D-arrays bilden eine entwicklung ueber die zeit ab. the values were coincidentally chosen (random), ausser des startpunktes einer 2D-nullkoordinate.
class time
{
//main method, arguments may be passed on commandline execution
public static void main(String args[])
{
// declare and initialize 4D array
int arr[][][][] = {
{
{ {0,0,0},{2,6,6},{7,4,2} },
{ {0,0,0},{9,6,2},{9,1,3} },
{ {0,0,0},{4,5,6},{2,5,2} }
},
{
{ {0,4,2},{2,6,1},{9,3,1} },
{ {3,7,9},{9,6,2},{0,1,5} },
{ {5,8,4},{4,7,6},{6,5,2} }
},
{
{ {7,5,2},{2,6,2},{6,5,5} },
{ {6,8,9},{7,5,2},{8,5,9} },
{ {2,8,5},{3,7,7},{4,5,8} }
}
};
// print time array in four nested for-loops
for (int l = 0; l<3; l++)
{
//print 3D-element number
System.out.println(l);
for (int i=0; i< 3 ; i++)
{
for (int j=0; j < 3 ; j++)
{
for (int k=0; k < 3; k++)
{
//print element
System.out.print(arr[l][i][j][k] + " ");
}
//print whitespaces
System.out.print(" ");
}
//newline
System.out.println();
}
}
}
}
3066 (just a quick rant)
spoiler alert on edx_HKUST_ex2
https://pastebin.com/pMsQc7pJ
3060 (lab03)
hong kong university edx comp102x lab3 solution
import comp102x.ColorImage;
import comp102x.Canvas;
public class Lab03
{
public void loadAnImage()
{
// Please write your code after this line
ColorImage labimg1 = new ColorImage();
int w, h;
w = labimg1.getWidth();
h = labimg1.getHeight();
Canvas canvas = new Canvas (w, h);
canvas.add(labimg1);
}
public void loadTwoImagesOnTheSameCanvas()
{
// Please write your code after this line
int w1, w2, h1, h2;
ColorImage labimg2 = new ColorImage();
ColorImage labimg3 = new ColorImage();
w1 = labimg2.getWidth();
h1 = labimg2.getHeight();
w2 = labimg3.getWidth();
h2 = labimg3.getHeight();
Canvas canvas2 = new Canvas ((2 * w1), h1);
canvas2.add(labimg2, 0, 0);
canvas2.add(labimg3, w1, 0);
}
public void imageAddition()
{
// Please write your code after this line
int ww1, ww2, hh1, hh2;
ColorImage labimg4 = new ColorImage();
ColorImage labimg5 = new ColorImage();
ColorImage labimg6 = labimg4.add(labimg5);
ww1 = labimg4.getWidth();
hh1 = labimg4.getHeight();
ww2 = labimg5.getWidth();
hh2 = labimg5.getHeight();
Canvas canvas3 = new Canvas (((3 * ww1) + 20), hh1);
canvas3.add(labimg4, 0, 0);
canvas3.add(labimg5, (ww1 + 10), 0);
canvas3.add(labimg6, ((ww1 * 2) + 20), 0);
}
public void imageMultiplication()
{
// Please write your code after this line
int width1, width2, height1, height2;
ColorImage labimg7 = new ColorImage();
ColorImage labimg8 = new ColorImage();
ColorImage labimg9 = labimg7.multiply(labimg8);
width1 = labimg7.getWidth();
height1 = labimg7.getHeight();
width2 = labimg8.getWidth();
height2 = labimg8.getHeight();
Canvas canvas4 = new Canvas (((3 * width1) + 20), height1);
canvas4.add(labimg7, 0, 0);
canvas4.add(labimg8, (width1 + 10), 0);
canvas4.add(labimg9, ((width1 * 2) + 20), 0);
}
public void changeColor()
{
ColorImage image = new ColorImage();
image.increaseRed(40);
Canvas canvas = new Canvas(image.getWidth(), image.getHeight());
canvas.add(image);
image.save();
}
}
3053 (simplest possible I/O from edx.org)
the java-I/O-class itself is not included
import comp102x.IO;
public class test10x
{
public static void main (String[] args)
{
double eingabe, ausgabe;
IO.output("bitte double:");
eingabe = IO.inputDouble();
ausgabe = eingabe;
System.out.println(ausgabe);
System.out.println("this is the end of the program");
}
}
3047 (datum_app, java, wiwi2005)
das programm besteht aus 2 klassen(application and dateobject) (eine dritte, die eingabeklasse ist nicht aufgeführt und an einer anderen stelle zu finden) und berechnet gedöns mit jahren und werktagen zwischen 1901-01-01 und 2100-12-31.
application
import java.util.*;
class datum_app {
public static void main (String[] args) {
int l = 6;
int m = 10;
int n = 1909;
int nowtag = 0;
int nowmonat = 0;
int nowjahr = 0;
int s,t,u,diff,nsumme,msumme,x,y,z,i,help,whelp,dhelp;
int wzaehler = 0;
GregorianCalendar GC = new GregorianCalendar();
System.out.println("Dieses Programm loest eine wiwi-Programmieraufgabe von 2005 (Stand: 17.12.2007), laeuft sequentiell ab und erwartet vom Benutzer einige Parameter.");
System.out.println("Zunaechst werden zwei Daten zwischen 1901-01-01 und 2100-12-31 im Format yyyy<return>mm<return>dd<return> erwartet.");
System.out.println("Es folgen einige debug-parameter der Datumsobjekte.");
System.out.println("Die zu loesenden Bedingungen werden angezeigt.");
System.out.println("Der Gregorianische Kalender wird nur zur HEUTE-Feststellung benutzt.");
System.out.println("Ein drittes Datum YYYY-MM-DD wird erwartet");
n = eingabe.readInt("Erstes Datum, Jahr:");
m = eingabe.readInt("Erstes Datum, Monat:");
l = eingabe.readInt("Erstes Datum, Tag:");
u = eingabe.readInt("Zweites Datum, Jahr:");
t = eingabe.readInt("Zweites Datum, Monat:");
s = eingabe.readInt("Zweites Datum, Tag:");
Datum ndatum = new Datum (l,m,n);
System.out.println("n");
System.out.println ("gueltig : " + ndatum.gueltig);
System.out.println (ndatum.jahr + "-" + ndatum.monat + "-" + ndatum.tag);
System.out.println (ndatum.tagesdiff);
System.out.println (ndatum.wochentag);
System.out.println ("Werktag : " + ndatum.werktag);
if (ndatum.schaltjahr) { System.out.println ("Schaltjahr"); }
else { System.out.println ("kein Schaltjahr"); }
System.out.println();
nowtag = GC.get(Calendar.DATE);
nowmonat = GC.get(Calendar.MONTH) + 1;
nowjahr = GC.get(Calendar.YEAR);
Datum heute = new Datum (nowtag, nowmonat, nowjahr);
System.out.println("und jetzt heute");
System.out.println ("gueltig : " + heute.gueltig);
System.out.println (heute.jahr + "-" + heute.monat + "-" + heute.tag);
System.out.println (heute.tagesdiff);
System.out.println (heute.wochentag);
System.out.println ("Werktag : " + heute.werktag);
if (ndatum.schaltjahr) { System.out.println ("Schaltjahr"); }
else { System.out.println ("kein Schaltjahr"); }
System.out.println();
Datum mdatum = new Datum (s,t,u);
System.out.println("m");
System.out.println ("gueltig : " + mdatum.gueltig);
System.out.println (mdatum.jahr + "-" + mdatum.monat + "-" + mdatum.tag);
System.out.println (mdatum.tagesdiff);
System.out.println (mdatum.wochentag);
System.out.println ("Werktag : " + mdatum.werktag);
if (ndatum.schaltjahr) { System.out.println ("Schaltjahr"); }
else { System.out.println ("kein Schaltjahr"); }
System.out.println();
if ((ndatum.gueltig == true) && (mdatum.gueltig == true)) {
if (ndatum.tagesdiff == mdatum.tagesdiff) help = 0;
else if (ndatum.tagesdiff < mdatum.tagesdiff) help = 1;
else help = 2;
switch (help) {
case 0 : {
System.out.println("(Punkt2)Beide Tage identisch. Differenz 0");
}
case 1 :
case 2 : {
diff = Math.abs(mdatum.tagesdiff - ndatum.tagesdiff);
System.out.println("(Punkt2)Die Differenz betraegt " + diff + " Tage");
}
default : {
break;
}
}//switch--help
}//if
else {
System.out.println ("(mindestens) eines der Daten ist ungueltig");
}
nsumme = ndatum.tagesdiff - ndatum.jahrsumme;
msumme = mdatum.tagesdiff - mdatum.jahrsumme;
System.out.println ("(Punkt 1) :");
System.out.println ("Tage seit 1. Januar " + ndatum.jahr + " (n) " + nsumme);
System.out.println ("Tage seit 1. Januar " + mdatum.jahr + " (m) " + msumme);
System.out.println ("Eingabe eines Datums in der Vergangenheit (Punkt 3)");
z = eingabe.readInt ("Jahr");
y = eingabe.readInt ("Monat");
x = eingabe.readInt ("Tag");
Datum past = new Datum (x,y,z);
if (!past.gueltig) System.out.println("Datum nicht gueltig");
else if (past.tagesdiff > heute.tagesdiff) {
System.out.println ("Datum liegt nicht in der Vergangenheit. Identische Daten hier kein Fehlerfall.");
}//if
else if (past.tagesdiff == heute.tagesdiff) {
if (heute.werktag == true) System.out.println("Daten identisch. Werktag.");
else System.out.println("Daten identisch. kein Werktag.");
}//else-if1
else if (Math.abs(past.tagesdiff - heute.tagesdiff) < 3) {
diff = (heute.tagesdiff - past.tagesdiff);
switch (diff) {
case 1 : {
if (past.werktag && heute.werktag) wzaehler = 2;
else if (past.werktag || heute.werktag) wzaehler = 1;
else wzaehler = 0;
break;
}
case 2 : {
dhelp = past.wtag;
switch (dhelp) {
case 1 :
case 2 :
case 3 :
case 4 : wzaehler = 2;
break;
case 5 : wzaehler = 1;
break;
case 6 : wzaehler = 0;
break;
case 7 : wzaehler = 1;
break;
default : break;
}//switch--dhelp
}
default : {
break;
}
}//switch--diff
}//else-if_diff3
else {
wzaehler = 1;
for (i=past.tagesdiff; i<heute.tagesdiff; i++) {
whelp = i;
Datum idate = new Datum (whelp);
if (idate.werktag) { wzaehler+=1; }
}//for
}//else
System.out.println ("Werktage von " + past.jahr + "-" + past.monat + "-" + past.tag + " bis heute (Punkt 3): " + wzaehler);
System.out.println ("Programmende. success");
}//main
}//class
objectclass
class Datum {
Boolean gueltig;
int tag;
int monat;
int jahr;
String wochentag;
Boolean werktag;
Boolean schaltjahr;
int tagesdiff;
int jahrsumme;
int wtag;
//Standard-Konstruktor
public Datum () {
gueltig = true;
tag = 6;
monat = 10;
jahr = 2012;
wochentag = "Samstag";
werktag = false;
schaltjahr = true;
tagesdiff = 40822;
}//Standard-Konstruktor
public Datum (int neuerTag, int neuerMonat, int neuesJahr) {
int i = 0;
int jahrdiff = 0;
tag = neuerTag;
monat = neuerMonat;
jahr = neuesJahr;
if ((jahr < 1901) || (jahr > 2100)) {
gueltig = false;
tag = 0;
monat = 0;
jahr = 0;
werktag = false;
schaltjahr = false;
}
else {
if ((jahr % 4) == 0) {
if ((jahr % 100) == 0) {
if ((jahr % 400) == 0) {
schaltjahr = true;
}//400
else { schaltjahr = false; }
}//100
else { schaltjahr = true; }
}//4
else { schaltjahr = false; }
switch (monat) {
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12 : {
if ((tag < 1) || (tag > 31)) {
gueltig = false;
tag = 0;
monat = 0;
jahr = 0;
}//if
else { gueltig = true; }
break;
}
case 4:
case 6 :
case 9 :
case 11 : {
if ((tag < 1) || (tag > 30)) {
gueltig = false;
tag = 0;
monat = 0;
jahr = 0;
}//if
else { gueltig = true; }
break;
}
case 2 : {
if (schaltjahr) { i = 29; }
else { i = 28; }
if ((tag < 1) || (tag > i)) {
gueltig = false;
tag = 0;
monat = 0;
jahr = 0;
}//if
else { gueltig = true; }
break;
}
default : {
gueltig = false;
break;
}
}//switch--monat
//Referenztag
if ((tag == 1) && (monat == 1) && (jahr == 1901)) { wochentag = "Dienstag"; werktag = true; tagesdiff = 1; }
else {
jahrdiff = jahr - 1901;
for (i=1901; i<jahr; i++) {
if ((i % 4) == 0) {
if ((i % 100) == 0) {
if ((i % 400) == 0) {
tagesdiff += 366;
}//400
else { tagesdiff += 365; }
}//100
else { tagesdiff += 366; }
}//4
else tagesdiff += 365;
}//for
jahrsumme = tagesdiff;
switch (monat) {
case 1 : {
tagesdiff += tag;
break;
}
case 3 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += tag;
}
break;
}
case 5 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
break;
}
case 7 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
break;
}
case 8 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += tag;
}
break;
}
case 10 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
break;
}
case 12 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += tag;
}
break;
}
case 4 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += tag;
}
break;
}
case 6 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += tag;
}
break;
}
case 9 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += tag;
}
break;
}
case 11 : {
if (schaltjahr) {
tagesdiff += 31;
tagesdiff += 29;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += tag;
}
else {
tagesdiff += 31;
tagesdiff += 28;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += 31;
tagesdiff += 30;
tagesdiff += 31;
tagesdiff += tag;
}
break;
}
case 2 : {
tagesdiff += 31;
tagesdiff += tag;
}
default : {
break;
}
}//switch--monat
i = tagesdiff % 7;
switch (i) {
case 0 : {
wochentag = "Montag";
wtag = 1;
break;
}
case 1 : {
wochentag = "Dienstag";
wtag = 2;
break;
}
case 2 : {
wochentag = "Mittwoch";
wtag = 3;
break;
}
case 3 : {
wochentag = "Donnerstag";
wtag = 4;
break;
}
case 4: {
wochentag = "Freitag";
wtag = 5;
break;
}
case 5 : {
wochentag = "Samstag";
wtag = 6;
break;
}
case 6 : {
wochentag = "Sonntag";
wtag = 7;
break;
}
default : {
wtag = -1;
break;
}
}//switch--i
switch (wtag) {
case 1 :
case 2 :
case 3 :
case 4 :
case 5 : {
werktag = true;
break;
}
case 6 :
case 7 : {
werktag = false;
break;
}
default : {
break;
}
}//switch--wtag
}//Referenztag-else
}//gueltiger Bereich
}//Konstruktor
public Datum (int tageszaehler) {
int i = 0;
if ((tageszaehler < 1) || (tageszaehler > 73049)) {
gueltig = false;
}
else {
i = tageszaehler % 7;
switch (i) {
case 0 : {
wtag = 2;
wochentag = "Dienstag";
werktag = true;
break;
}
case 1 : {
wtag = 3;
wochentag = "Mittwoch";
werktag = true;
break;
}
case 2 : {
wtag = 4;
wochentag = "Donnerstag";
werktag = true;
break;
}
case 3 : {
wtag = 5;
wochentag = "Freitag";
werktag = true;
break;
}
case 4 : {
wtag = 6;
wochentag = "Samstag";
werktag = false;
break;
}
case 5 : {
wtag = 7;
wochentag = "Sonntag";
werktag = false;
break;
}
case 6 : {
wtag = 1;
wochentag = "Montag";
werktag = true;
break;
}
default : {
break;
}
}//switch--i
}//gueltig
}//Konstruktor2
}//class Datum
2981 (password management in java)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
class j2_app {
public static void main (String[] args) {
int menueingabe, sid, uid;
char t_input;
String tabelle, sname, ip, er, user, pass;
menueingabe = 0;
t_input = ' ';
while (menueingabe != 5) {
do {
System.out.println ("1 Datensatz anlegen\n2 Datensatz bearbeiten\n3 Datensatz loeschen\n4 Tabelle anzeigen\n5 Programm beenden\n");
try {
menueingabe = eingabe.readInt("Ihre Wahl:");
}
catch (NumberFormatException e) {
System.out.println("NumberFormatException in main");
}
} while ((menueingabe != 1) && (menueingabe != 2) && (menueingabe != 3) && (menueingabe != 4) && (menueingabe != 5));
if (menueingabe != 5) {
do {
System.out.println ("Tabelle:\ns server\nu user\n");
t_input = eingabe.readChar ("Ihre Wahl:");
} while ((t_input != ('s')) && (t_input != ('u')));
switch (t_input){
case 's' : tabelle = "server"; break;
case 'u' : tabelle = "user"; break;
default: tabelle = "not_defined";
System.out.println ("caught");
}
switch (menueingabe) {
case 1: System.out.println("eins");
System.out.println (tabelle);
if (t_input=='s') { //Datensatz anlegen *server*
System.out.println ("Datensatz anlegen in Tabelle \'server\'");
er = eingabe.readString("");
System.out.println();
sname = eingabe.readString ("url:");
System.out.println ("url:" + sname);
ip = eingabe.readString ("ip:");
System.out.println ("ip:" + ip);
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
stmt.executeUpdate("INSERT INTO server (url, ip) VALUES ('" + sname + "', '" + ip + "')" );
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
System.out.println ("written to database");
}
else { //Datensatz anlegen *user*
System.out.println("Datensatz anlegen in Tabelle \'user\'");
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT sid, url FROM server" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
er = eingabe.readString("");
System.out.println();
sid = eingabe.readInt ("serverzuordnung(sid):");
System.out.println("sid:" + sid);
user = eingabe.readString ("user:");
System.out.println("user:" + user);
pass = eingabe.readString ("password:");
System.out.println("password:" + pass);
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
conn = null;
stmt = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
stmt.executeUpdate("INSERT INTO user (sid, user, password) VALUES (" + sid + ", '" + user + "', '" + pass + "')" );
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
System.out.println ("written to database");
}
break;
case 2: System.out.println ("zwei");
System.out.println (tabelle);
if (t_input=='s') { //Datensatz bearbeiten *server*
System.out.println("Datensatz bearbeiten \'server\'");
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT sid, url, ip FROM server" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
er = eingabe.readString("");
System.out.println();
sid = eingabe.readInt("Bearbeite sid:");
System.out.println("sid:" + sid);
sname = eingabe.readString("neues Feld url:");
System.out.println("url:" + sname);
ip = eingabe.readString("neues Feld ip:");
System.out.println("ip:" + ip);
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
conn = null;
stmt = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
stmt.executeUpdate("UPDATE server SET url = '" + sname + "', ip = '" + ip + "' WHERE sid = '" + sid + "'");
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
System.out.println ("written to database");
}
else { //Datensatz bearbeiten *user*
System.out.println("Datensatz bearbeiten \'user\'");
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT uid, user FROM user" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
er = eingabe.readString("");
System.out.println();
uid = eingabe.readInt("Bearbeite uid:");
System.out.println("uid:" + uid);
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
conn = null;
stmt = null;
rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT sid, url FROM server" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
sid = eingabe.readInt("neues Feld sid:");
System.out.println("sid:" + sid);
user = eingabe.readString("neues Feld user:");
System.out.println("user:" + user);
pass = eingabe.readString("neues Feld password:");
System.out.println("password:" + pass);
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
conn = null;
stmt = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
stmt.executeUpdate("UPDATE user SET sid = '" + sid + "', user = '" + user + "', password = '" + pass + "' WHERE uid = '" + uid + "'");
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
System.out.println ("written to database");
}
break;
case 3: System.out.println ("drei");
System.out.println (tabelle);
if (t_input=='s') { //Datensatz loeschen *server*
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT sid, url, ip FROM server" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
er = eingabe.readString("");
System.out.println();
sid = eingabe.readInt("loeschen(sid):");
System.out.println("sid:" + sid);
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
conn = null;
stmt = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
stmt.executeUpdate("DELETE FROM server WHERE sid = '" + sid + "'");
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
System.out.println ("deleted from database");
}
else { //Datensatz loeschen *user*
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT uid, sid, user, password FROM user" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
er = eingabe.readString("");
System.out.println();
uid = eingabe.readInt("loeschen(uid):");
System.out.println("uid:" + uid);
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
conn = null;
stmt = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
stmt.executeUpdate("DELETE FROM user WHERE uid = '" + uid + "'");
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
System.out.println ("deleted from database");
}
break;
case 4: System.out.println ("vier");
System.out.println (tabelle);
if (t_input=='s') { //Tabelle anzeigen *server*
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT sid, url, ip FROM server" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
else { //Tabelle anzeigen *user*
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
System.out.println ("driverconnection failed...");
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jtest?" + "user=root");
// Do something with the Connection
try {
stmt = conn.createStatement();
try {
rs = stmt.executeQuery( "SELECT uid, sid, user, password FROM user" );
int j = 1;
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
System.out.println (j);
for ( int i = 1 ; i <= numColumns ; i++ ) {
String columnName = rs.getMetaData().getColumnName(i);
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " " + columnName + "\t" + " = " + rs.getObject(i) );
}
j++;
}
} finally {
try { rs.close(); } catch (Throwable ignore) { System.out.println ("rs.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { System.out.println ("stmt.close() failed"); } /* Propagate the original exception instead of this one that you may want just logged */
}
} finally { //It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { System.out.println ("conn.close() failed"); } /* Propagate the original exception
instead of this one that you may want just logged */
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
break;
default: System.out.println("caught");
}
}
if (menueingabe != 5) { er = eingabe.readString (""); }
System.out.println();
}
System.out.println ("Programm wird beendet");
}
}

