SQL Exception: Cursor position not valid

Status
Nicht offen für weitere Antworten.

rhöner

Mitglied
Hallo,

ich versuche über eine Datenbankabfrage fünf Felder zu füllen. Man gibt die Kunden-Nr. ein, anschließend auf "suchen" und dann sollen die Felder mit der Adresse gefüllt werden. Ich bekomme aber ständig eine SQLException: Cursor position not valid.
Ich kann aber meinen Fehler nicht finden. Kann mir jemand weiterhelfen?

Hier mein Code:
Code:
public void onLieferantSuchen (ActionEvent event) {
		Connection con;
		try {
			Class.forName("com.ibm.as400.access.AS400JDBCDriver");
			con=DriverManager.getConnection("jdbc:as400://10.0.1.199;libraries=" + Datenbank , "User", "Password");
			Statement statement=con.createStatement();
			String sql = null;
			sql = "select kdan1, kdstr, kdlort, kdplz, kdlakz from pkunden where kdkonz='xxx' and kdfirm='xxx' and kdkdnr='" + getKdnr() + "' and kdkdli=2";
			ResultSet res = statement.executeQuery(sql);
			setName(res.getString("kdan1"));
			setStrasse(res.getString("kdstr"));
			setPlz(res.getString("kdplz"));
			setOrt(res.getString("kdlort"));
			setLkz(res.getString("kdlakz"));
		}
		catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		}
		catch (SQLException e2) {
			e2.printStackTrace();
		}
		catch (ArrayIndexOutOfBoundsException e3) {
			Statusbar.outputMessage("Kein Datensatz gefunden.");
		}
	}
 
S

SlaterB

Gast
in einem ResultSet gibt es 0-n einzelne Ergebnisse,

bevor du mit res.getString("kdan1"); etwas abfragen kannst,
musst du erstmal festlegen, welchen Eintrag du meinst,

man könnte denken, dass initial der erste ausgewählt ist,
das ist aber nicht so, könnte auch gar keiner da sein,
erst muss man next() aufrufen und am besten den boolean-Rückgabewert bedenken

Tutorial?
 
S

SlaterB

Gast
tja, das ist ne Schleife,
ob du ne Schleife willst oder nicht musst du selber wissen,

ich glaube, ich habe mein Anliegen deutlich gemacht:
1x res.next() aufrufen, hier der komplette Code:

res.next();


sorry ;)
 

sparrow

Top Contributor
Je nach Datenbank steht der Cursor manchmal vor dem ersten Datensatz bei einem ResultSet.
Erfragen kann man das mit rs.isBeforeFirst();

Gruß
Sparrow
 

HoaX

Top Contributor
was du noch ändern solltest:
1) preparedstatement verwenden, so wies jetzt ist kann der benutzer sql-befehle einschleusen
2) du schließt dein resultset/statement/connection nicht
3) ich denke nicht dass das diene einzige db-methode ist oder? schreibst du in jede die zugangsdaten? mach das doch mal zentral, sonst musst du das am ende an 20+ stellen ändern...
 

rhöner

Mitglied
zu
1) preparedstatement sagt mir persönlich gar nix. Hab aber auch noch nicht wirklich lange mit Java bzw. SQL zu tun.
2) wird jetzt geschlossen
3) wird jetzt zentral gemacht

Danke für die Tipps.
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
KOKASS Exception bei Datenbankconnect Datenbankprogrammierung 9
Kirby.exe SQL-Exception: Column not found Datenbankprogrammierung 6
S MySQL hibernate exception: illegal state exception : entityManagerFactory is closed Datenbankprogrammierung 5
G MySQL Java Problem: Nullpointer Exception obwohl Daten vorhanden sind? Datenbankprogrammierung 2
G PostgreSQL Nach Monaten auf einmal ClassNotFound-Exception Datenbankprogrammierung 3
K JPA Projekt Exception Datenbankprogrammierung 7
C jpa, exception Predeployment of PersistenceUnit failed Datenbankprogrammierung 1
M CommunicationLinkError - NullPointer Exception Datenbankprogrammierung 11
T MongoDB: Morphia REST 505 Exception Tomcat Datenbankprogrammierung 2
M SQL-Exception trotz funktionierendem SELECT Datenbankprogrammierung 4
N JDBC: rollback() bei Exception geht nicht!? Datenbankprogrammierung 1
M SQL Exception Datenbankprogrammierung 6
L Probleme mit DriverManager.getConnection(..) - Endlosschleife, Java Absturz, Keine Exception Datenbankprogrammierung 4
D Hibernate SaveOrUpdate Exception Datenbankprogrammierung 2
E MySQL Hibernate mit JaxWS führt zu LazyInitialization Exception Datenbankprogrammierung 8
E PostgreSQL Exception too ...many clients already bei DB-Abfrage Datenbankprogrammierung 14
T java sql exception getDate() Datenbankprogrammierung 2
O Viele Verbindungen-Exception bei insert Daten zur MySQL-Datenbank Datenbankprogrammierung 2
E Sql Exception Datenbankprogrammierung 14
M NestedTransaction- Exception in Hibernate Datenbankprogrammierung 15
F Derby/JavaDB SQL-Exception...Aber wieso!? :/ Datenbankprogrammierung 2
T Exception ResultSet Datenbankprogrammierung 7
Paristick MSSQL - JDBC Exception beim Registrieren Datenbankprogrammierung 5
S Null Pointer exception statement Datenbankprogrammierung 8
G JDBC Exception Datenbankprogrammierung 3
S ResultSet einer Datenbankabfrage - Nullpointer Exception Datenbankprogrammierung 13
F Derby/JavaDB Exception - Cannot accept Null Value (help) Datenbankprogrammierung 10
G Stored Procedure Exception Handling Datenbankprogrammierung 3
C SQL Exception auf Unique überprüfen Datenbankprogrammierung 5
B Hibernate+JPA Exception in persistence.xml Datenbankprogrammierung 5
L SQL Exception Problem Datenbankprogrammierung 7
M hilfe zur einer Exception Datenbankprogrammierung 2
J Nullpointer Exception bei Zugriff auf Datenbank Datenbankprogrammierung 13
A MySQL Anbindung - Exception Handling Datenbankprogrammierung 2
O Oracle 11g wirft bei 90 % der installation eine Exception ? Datenbankprogrammierung 5
R Warum kommt eine Exception bei instanceof ? Datenbankprogrammierung 4
B SQL Exception Datenbankprogrammierung 9
E Datenbankverbindung Java MySQL Exception Datenbankprogrammierung 10
N Class not found Exception Datenbankprogrammierung 2
A Exception in thread "AWT-EventQueue-0" java.lang.N Datenbankprogrammierung 4
M SQL Exception bei LIMIT Datenbankprogrammierung 11
megachucky Problem mit: SQL Exception Before start of result set Datenbankprogrammierung 2
W updateRow() schmeißt eine Exception, weil schreibgeschützt Datenbankprogrammierung 6
M Sql Anfrage wirft Exception Datenbankprogrammierung 5
6 Communications link failure due to underlying exception Datenbankprogrammierung 10
R SQL Exception "Weiterleiten der Egebnissmenge" Datenbankprogrammierung 15
märliprinz Exception in thread "main" java.lang.OutOfMemoryEr Datenbankprogrammierung 9
S Java SQL-Exception bei Zugriff auf MSAccess Datenbankprogrammierung 2
K Exception bei Verbindungsaufbau Oracle Datenbank Datenbankprogrammierung 13
L "desc tablename" liefert SQL Exception mit execute Datenbankprogrammierung 6
M SQL Exception Datenbankprogrammierung 3
M Problem mit dem ActionListener und SQL Exception Datenbankprogrammierung 6
D Exception bei ResultSet.moveToInsertRow Datenbankprogrammierung 6
EagleEye problem mit exception Datenbankprogrammierung 2
L UPDATE löst Exception aus Datenbankprogrammierung 6
V Exception beim Speichern von eingegebenen Daten in Tabelle Datenbankprogrammierung 2
G ich bekomm immer die exception grrrr Datenbankprogrammierung 3
D Unklare SQL Exception Datenbankprogrammierung 3
A Maximale Anzahl offener Cursor überschritten Datenbankprogrammierung 5
S SQLite Selectanfrage lieft datensatz aber cursor ist leer Datenbankprogrammierung 2
Y java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state Datenbankprogrammierung 2
K DB2 Mit Cursor auf die DB Datenbankprogrammierung 19
A Maximale Anzahl offener Cursor überschritten Datenbankprogrammierung 4
C Stored Procedure - Cursor Datenbankprogrammierung 2
S Datenbank zugriff optimieren - zugriff ohne cursor? Datenbankprogrammierung 7
E zu viele offene Cursor, die II. Datenbankprogrammierung 3
E Maximale Anzahl offener Cursor Datenbankprogrammierung 9
L Invalid cursor state Datenbankprogrammierung 9
A Maximale Anzahl offener Cursor erreicht Datenbankprogrammierung 3
J Derby Cursor Problem Datenbankprogrammierung 2
märliprinz JDBC Cursor Datenbankprogrammierung 5
P Tuple position Datenbankprogrammierung 7

Ähnliche Java Themen

Neue Themen


Oben