seriously
seriously

Reputation: 355

Insert data from Java into Access with jdbc

This is my first question at this great site :D

I have an access database. In this database there is a table with 4 teams in a column. These teams have points and i want to sort out the first two teams with the most points. And finally insert these two teams in another table.

I can fetch these two teams without any problems. But if i try inserting them into another table, it shows a mistake: "java.sql.SQLException: Invalid Cursor Type: 1003"

public void Viertelfinale()
    {
        final String [] temp = new String[20];

        int i=0;

        try {
            st = con.createStatement();
            String sql = "SELECT * FROM tbl_Spielplan ORDER BY A_Punkte DESC";
            rs = st.executeQuery(sql);

            while (rs.next()){
                temp[i] = rs.getString("A_Teams");
                i++;
            }

            rs.close();
            st.close();
            int j=0;
            st = con.createStatement();
            String sql1 = "SELECT * FROM tbl_Viertelfinale";
            rs = st.executeQuery(sql1);

            rs.next();
            rs.moveToInsertRow();
            rs.updateString("A_Teams", temp[0]);
            rs.insertRow();

            rs.next();
            rs.moveToInsertRow();
            rs.updateString("A_Teams", temp[1]);
            rs.insertRow();


        } catch (SQLException e) {
            e.printStackTrace();
        }
    }  

Sorry for my English :/

Error:

java.sql.SQLException: Invalid Cursor Type: 1003
    at sun.jdbc.odbc.JdbcOdbcResultSet.moveToInsertRow(JdbcOdbcResultSet.java:4306)
    at Turnier.Schultunier.Viertelfinale(Schultunier.java:49)
    at Turnier.Viertelfinale.<init>(Viertelfinale.java:94)
    at Turnier.Viertelfinale$1.run(Viertelfinale.java:35)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Upvotes: 0

Views: 256

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201457

I'm pretty sure that Access doesn't support SELECT FOR UPDATE which seems to be what you're trying to use. Instead, just use a plain UPDATE statement (in addition to your SELECT query).

Upvotes: 1

Related Questions