Reputation: 1378
I have an issue I'm facing with Vertica JDBC Driver I try to store data into my DB - but sometimes the data isn't stored at all and I don't get any error its appear to be succeeded. it also happens when I try to use a file.
This seems to be a major bug - which against the 4 pillar of Data managment. sample code is attached.
How can I 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 all on " + tableName + " to 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 + " FROM stdin WITH 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 IS " + vcs.getRejects().size());
vcs.execute();
ResultSet rs = st.executeQuery("SELECT count(1) FROM " + tableName);
while (rs.next()) {
int count = rs.getInt(1);
System.out.println("result = " + count);
}
rs.close();
// st.execute("drop table " + tableName);
}
}
Upvotes: 0
Views: 440
Reputation: 3609
The Vertica copy statement doesn't behave like a traditional SQL INSERT statement. COPY doesn't fail, but reports rows that couldn't be inserted.
That's wise : let's say you want to insert 10 millions rows, you may not want it to fail fail because a single line is invalid.
To deal with the insertion errors, you have several options :
Upvotes: 2