UpdateString not implemented by SQLite JDBC driver

I have a table PERSONwith more than 5 million rows, and I need to update the field NICKNAMEfor each of them based on the field NAMEinside the same table.

ResultSet rs = statement.executeQuery("select NAME from PERSON");
while(rs.next())
{
    // some parsing function like:
    // Nickname = myparsingfunction(rs.getString("NAME"));
    rs.updateString( "NICKNAME", Nickname );
    rs.updateRow();
}

But I got this error:

not implemented by SQLite JDBC driver

I am using sqlite-jdbc-3.8.11.2.jar downloaded at https://bitbucket.org/xerial/sqlite-jdbc/downloads .

I know that I can use the following SQL query:

statement.executeUpdate("update PERSONS set NICKNAME = Nickname where ID = Id");

But it will take forever, and I understand that the update ResultSetwill be faster. So, what parameters do I need to update in the fastest way? Any other driver available? Should I navigate from Java?

UPDATE

, . CASE END , SQL-, .

update  PERSON
set     NICKNAME= case ID                        
                        when 173567 then 'blabla'
                        when 173568 then 'bleble'
                        ...
                        when 173569 then 'blublu'
                    end
where ID in (173567, 173568, 173569)
+4
1

, SQLite JDBC- updateString. .

:

  • , , . ( PreparedStatement.addBatch()) (tutorial).
  • myparsingfunction SQL, UPDATE PERSONS SET NICKNAME = some_function(NAME).
  • ( org.sqlite.Function), Java, SQL. , :

    Function.create(db.getConnection(), "getNickName", new Function() {
        protected void xFunc() throws SQLException {
            String name = value_text(0);
            String nickName = ...; // implement myparsingfunction here
            result(nickName);
        }
    });
    

    : UPDATE PERSONS SET NICKNAME = getNickName(NAME);

SQLite , .

, (, SQL , ). , , .

+3

Source: https://habr.com/ru/post/1610165/


All Articles