Using Sybase JConnect: ENABLE_BULK_LOAD

Can someone provide an example of bulk inserts via JConnect (s ENABLE_BULK_LOAD) in Sybase ASE?

I browsed the internet and found nothing.

+3
source share
5 answers

I contacted one of Sybase's engineers and they provided me with a sample code. Therefore, I can answer my question.

Basically, an example is given here, since the example code is quite large ... This involves a lot of pre-initialized variables, but otherwise it will be several hundred lines. Anyone interested should get this idea. This can give up to 22K inserts per second in an ideal world (Sybase anyway).

SybDriver sybDriver = (SybDriver) Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
sybDriver.setVersion(com.sybase.jdbcx.SybDriver.VERSION_6);
DriverManager.registerDriver(sybDriver);

//DBProps (after including normal login/password etc.
props.put("ENABLE_BULK_LOAD","true");

//open connection here for  sybDriver

dbConn.setAutoCommit(false);    
String SQLString = "insert into batch_inserts (row_id, colname1, colname2)\n values (?,?,?) \n";

PreparedStatement   pstmt;
try
{
   pstmt = dbConn.prepareStatement(SQLString);      
}
catch (SQLException sqle)
{
   displaySQLEx("Couldn't prepare statement",sqle);
   return;
}

for (String[] val : valuesToInsert)
{
   pstmt.setString(1, val[0]);  //row_id    varchar(30)
   pstmt.setString(2, val[1]);//logical_server varchar(30)
   pstmt.setString(3, val[2]);  //client_host varchar(30)

   try
   {
      pstmt.addBatch();
   }
   catch (SQLException sqle)
   {
      displaySQLEx("Failed to build batch",sqle);
      break;
   }
}

try {
   pstmt.executeBatch();
   dbConn.commit();
   pstmt.close();
} catch (SQLException sqle) {
   //handle
}

try {
   if (dbConn != null)
      dbConn.close();
} catch (Exception e) {
   //handle
}
+7
source

To get the sample provided by Chris Cannon, remember to turn off auto-lock mode first:

dbConn.setAutoCommit(false);

And put the following line before dbConn.commit ():

pstmt.executeBatch();

Otherwise, this method will only slow down the insertion.

+2
source

~ 100-1000rows . : * [5000rows in 500batches]: 1716ms = ~ 2914rows . ( !).

db (i7 ), :

CREATE TABLE
archive_account_transactions
(
account_transaction_id INT,
entered_by INT,
account_id INT,
transaction_type_id INT,
DATE DATETIME,
product_id INT,
amount float,
contract_id INT NULL,
note CHAR(255) NULL
)

account_transaction_id (pk), account_id, DATE, contract_id.

, , , :

jdbc:sybase:Tds:40.1.1.2:5000/ikp?EnableBatchWorkaround=true;ENABLE_BULK_LOAD=true   

.addBatch, , , java StringBuilder sql , execute. insert , , , , . Enable_bulk_load , EnableBatchWorkaround DYNAMIC_PREPARE = ​​false, , .

, , ! , - , , , ? - , , sybase, mysql 16 000 , " " .

Rod

+2

, Java, LOAD TABLE SQL. Sybase ASA JConnect.

0

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


All Articles