Hallo alle,
ich möchte die Datenbank update mit ResultSet, aber funktioniert die update Funktionen von ResultSet irgendwie nicht. Ich weiß nicht, wo der Fehler ist. Könnt ihr für mich mal gucken?
Der Fehlermeldung ist: com.mysql.jdbc.NotUpdatable: Result Set not updatable (referenced table has no primary keys).This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details
meine Table ist einfach:
name | age
-------------------
A 30
B 20
...
...
----------------------
Hier ist meine ganze Code. Der Fehler kommt aus Zeile 24.
ich möchte die Datenbank update mit ResultSet, aber funktioniert die update Funktionen von ResultSet irgendwie nicht. Ich weiß nicht, wo der Fehler ist. Könnt ihr für mich mal gucken?
Der Fehlermeldung ist: com.mysql.jdbc.NotUpdatable: Result Set not updatable (referenced table has no primary keys).This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details
meine Table ist einfach:
name | age
-------------------
A 30
B 20
...
...
----------------------
Hier ist meine ganze Code. Der Fehler kommt aus Zeile 24.
Java:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class UpdatableResultSetDemo {
public static void main(String[] args) {
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "");
Statement statement = connection.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String query = "SELECT * from Friends";
ResultSet uprs = statement.executeQuery(query);
uprs.first();
uprs.updateInt(2, 80); // Hier kommt der Fehler! Aber warum????!!!
uprs.updateRow();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Zuletzt bearbeitet: