java - Vertica Jdbc driver NOT throwing - SQL state: 22001 when ERROR: value too long for type -


i have issue i'm facing vertica jdbc driver try store data db - data isn't stored @ , don't error appear succeeded. happens when try use file.

this seems major bug - against 4 pillar of data managment. sample code attached.

how can solve this?

public class verticatest {     public static void main(string[] args) throws exception     {         class.forname("com.vertica.jdbc.driver");         string tablename = "vertica_test1";         java.sql.connection connection = drivermanager.getconnection("jdbc:vertica://xyz.qwe.com:5433/db?tcpkeepalive=true", "user", "admin");         java.sql.statement st = connection.createstatement();         st.execute("create table " + tablename + " (test_name varchar(10))");         st.execute("grant on " + tablename + " public ");         string value = "short";         if (true) {             value = "543543543 sun aug 11 065650 utc 207657657650";         }         inputstream stream = new bytearrayinputstream(value.getbytes(standardcharsets.utf_8));         string copy = "copy " + tablename + " stdin  parser libcsvparser() abort on error no commit";         verticacopystream vcs = new verticacopystream((verticaconnection) connection, copy);         vcs.start();         vcs.addstream(stream);         system.out.println("reject size row " + vcs.getrejects().size());         vcs.execute();         resultset rs = st.executequery("select count(1) " + tablename);         while (rs.next()) {             int count = rs.getint(1);             system.out.println("result = " + count);         }         rs.close();         // st.execute("drop table " + tablename);     }  } 

the vertica copy statement doesn't behave traditional sql insert statement. copy doesn't fail, reports rows couldn't inserted.

that's wise : let's want insert 10 millions rows, may not want fail fail because single line invalid.

to deal insertion errors, have several options :

  • the "abort on error" parameter allows fail whole copy command 1 error occurs
  • with java, tend use insert prepared statement (which behind scenes uses copy), documented here. preparedstatement.executebatch(); returns array of int representing success/failure of each processed row.
  • other strategies deal copy errors documented here.

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -