Last active
January 8, 2019 12:06
-
-
Save BlkPingu/e450e133d2cd2fa119cc529297cd1c60 to your computer and use it in GitHub Desktop.
jdbc result set iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Showsingle(){ | |
boolean next = true; | |
try { | |
Class.forName( DRIVER ); | |
c = DriverManager.getConnection( Connection, user, passwort ); | |
System.out.println( "Opened database successfully" ); | |
stmt = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, | |
ResultSet.CONCUR_UPDATABLE);//Zum Durchiterieren TYPE_SCROLL_INSENSITIVE | |
ResultSet rs = stmt.executeQuery( "SELECT * FROM standort;" ); | |
while (next == true) { | |
System.out.println( "nächster eintrag n voriger p q for exit" ); | |
Scanner scanner = new Scanner(System.in); | |
String scanner2 = scanner.nextLine(); | |
if(scanner2.equals("n")) { | |
rs.next(); | |
System.out.println( rs.getString( "sname" ) + " | " + rs.getString( "sort" ) + " | " + rs.getString( "sstrasse" ) + " | " + rs.getString( "sdurchwahl" ) + " | " + rs.getString( "smail" ) + " | " + rs.getString( "sland" ) ); | |
} | |
else if(scanner2.equals("p") ){ | |
rs.previous(); | |
System.out.println( rs.getString( "sname" ) + " | " + rs.getString( "sort" ) + " | " + rs.getString( "sstrasse" ) + " | " + rs.getString( "sdurchwahl" ) + " | " + rs.getString( "smail" ) + " | " + rs.getString( "sland" ) ); | |
}else if(scanner2.equals("q")) | |
{return;} | |
else | |
{ | |
System.out.println( "wrong entrance" ); | |
} | |
} | |
} catch (Exception e) { | |
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); | |
System.exit( 0 ); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment