try {
sessionOracle = BaseDAO.getHibernateSession().openSession();
sessionPostgres = BaseDAOgis.getHibernateSession().openSession();
int id = 0;
JSONArray jaRoute = new JSONArray();
for (int i = 0; i < dataHolder.size(); i++) {
JSONObject jo = new JSONObject();
try{
jo.put("routeNo", (int) list.get(0));
jo.put("routeName", list.get(1).toString());
jo.put("stopSequenceID", (int) list.get(2));
jo.put("stopID", (int) list.get(3));
jo.put("stopName", list.get(4).toString());
jo.put("lat", (double) list.get(5));
jo.put("lon", (double) list.get(6));
System.out.println(jo.length() + "" +cellStoreVector.size());
if(jo.length()!=cellStoreVector.size())
{
System.out.println(jo.length() + "if" +cellStoreVector.size());
joOutput.put("success", true);
joOutput.put("error", true);
joOutput.put("size", false);
return joOutput;
}
}
catch(Exception e){
System.out.println("EXCEWs");
System.out.println(e);
joOutput.put("success", true);
joOutput.put("error", true);
joOutput.put("size", false);
return joOutput;
}
jaRoute.put(jo);
}
System.out.println("DB");
txPostgres = sessionPostgres.beginTransaction();
txOracle= sessionOracle.beginTransaction();
for (int i = 0; i < jaRoute.length(); i++) {
direction = "U";
JSONObject first = jaRoute.getJSONObject(i);
routeNo = first.getString("routeNo");
System.out.println();
int no = Integer.parseInt(routeNo);
routeName = first.getString("routeName");
stopSequenceID = first.getString("stopSequenceID");
stopID = first.getString("stopID");
stopName = first.getString("stopName");
lat = first.getString("lat");
lon = first.getString("lon");
if(i < jaRoute.length() - 1)
second = jaRoute.getJSONObject(i + 1);
System.out.println("id"+ id);
if(Integer.parseInt(first.getString("routeNo"))!= id){
try{
String sqlRouteMaster = "insert into route_master(route_id, route_name, direction, route_status, route_no, ROUTE_EFCTV_FROM_DT,Source_stop_id,dest_stop_id,ROUTE_TYPE,city_operational) "
+ "values('"
+ routeNo
+ "','"
+ routeName
+ "','"
+ direction1
+ "','"
+ routeStatus
+ "','"
+ routeName.trim().substring(0, 9)
+ "',now(),'"+1038+"','"+1039+"','"+37+"','"+false+"')";
String sqlMRoute="insert into m_route(route_id, route_name, direction, route_status, route_no, ROUTE_EFCTV_FROM_DT,source_stop_id, dest_stop_id,ROUTE_TYPE,CITY_TYPE) "
+ "values('"
+ routeNo
+ "','"
+ routeName
+ "','"
+ direction
+ "','"
+ routeStatus
+ "','"
+ routeName.trim().substring(0, 9)
+ "', current_timestamp,'"+1038+"','"+1039+"','"+37+"','"+97+"')";
int list4=sessionPostgres.createSQLQuery(sqlRouteMaster)
.executeUpdate();
System.out.println(list4);
int list5=sessionOracle.createSQLQuery(sqlMRoute).executeUpdate();
System.out.println(list5);
}catch(Exception ii){
}finally{}
if(Integer.parseInt(second.getString("routeNo")) == id || id == 0){
double endLat = Double.parseDouble(second
.getString("lat"));
double endLon = Double.parseDouble(second
.getString("lon"));
theGeom = getMultiLineString(startLat, startLon,
endLat, endLon);
if (theGeom.length() > 0) {
System.out.println("rout");
sqlRouteDetails = "insert into route_details(route_seq_no,route_id,stop_seq_no,stop_id,location,lat,lon,the_geom,stop_type_id,REF_DISTANCE,REF_TIME,STOP_TIME)"
+ " values('"
+ routSeqNo
+ "','"
+ routeNo
+ "','"
+ stopSequenceID
+ "','"
+ stopID
+ "','"
+ stopName
+ "','"
+ lat
+ "','"
+ lon
+ "',ST_SetSRID(ST_GeomFromText('"
+ theGeom
+ "'),4326),'"
+ stopTypeId
+ "','"
+ refDistance
+ "','" + refTime + "','" + stopTime + "')";
} else {
System.out.println(id);
sqlRouteDetails = "insert into route_details(route_seq_no,route_id,stop_seq_no,stop_id,location,lat,lon,stop_type_id,REF_DISTANCE,REF_TIME,STOP_TIME)"
+ " values('"
+ routSeqNo
+ "','"
+ routeNo
+ "','"
+ stopSequenceID
+ "','"
+ stopID
+ "','"
+ stopName + "','" + lat + "','" + lon + "','"+stopTypeId+"','"+refDistance+"','"+refTime+"','"+stopTime+"')";
}
id=Integer.parseInt(first.getString("routeNo"));
String sqlMRouteDtl="insert into m_route_dtl(route_seq_no,route_id, stop_seq_no, stop_id,stop_type_id,REF_DISTANCE,REF_TIME,STOP_TIME) "
+ "values('"+mRouteSql+"','"+routeNo+"','"+stopSequenceID+"','"+stopID+"','"+stopTypeId+"','"+refDistance+"','"+refTime+"','"+stopTime+"')";
sessionPostgres.createSQLQuery(sqlRouteDetails).executeUpdate();
sessionOracle.createSQLQuery(sqlMRouteDtl).executeUpdate();
routSeqNo++;
}
//
txOracle.commit();
//
txPostgres.commit();
joOutput.put("success", true);
joOutput.put("error", false);
} catch (Exception i) {
i.printStackTrace();
//
txPostgres.rollback();
//
txOracle.rollback();
joOutput.put("success", false);
joOutput.put("error", false);
} finally {
try {
sessionPostgres.close();
sessionOracle.close();
} catch (Exception e) {
e.printStackTrace();
}
return joOutput;
}
}
forthe first time or twice , appLicaton is running fine but if we are trying For next time it is stuck at
Hibernate: insert into m_route(route_id, route_name, direction, route_status, route_no, ROUTE_EFCTV_FROM_DT,source_stop_id, dest_stop_id,ROUTE_TYPE,CITY_TYPE) values(?,?,?,?,?,?,?,?,?,?,?)
And again we are restarting Oracle db then again same thing. once or twice running and stuck.
please help me.
Thanks in advance.
I could not able to find the problem. Why its locking/ postgres and oracle.
route_master and route_details are Postgres tables and
m_route and m_route_dtl
are Oracle tables
First of all why you are using plain sql when have Hibernate in the project? its just not efficient.
Second based on code you provided you opening new hibernate session each time, try initilize it just once.
Finally can you log on admin account on oracle/postgres and check what is actually going on when apllication gets stuck ?
Related
Currently I am working on a solution to read a 454 character/line based huge file (minimum 50000 rows) via Java.As per the requirement it is a positioned based file, we first need to read the file , then parse the position based values and need to insert into a table. (minimum 96 positions will be inserted into 96 columns of the table).
I took this concept after the parsing.
[ INSERT ALL INTO<TABLE NAME> [COL1,COL2,COL3] Values [VAL1,VAL2,VAL3]
INTO<TABLE NAME> [COL1,COL2,COL3] Values [VAL1,VAL2,VAL3]
SELECT * FROM DUAL;]
Here is my code:
try{
char[] line = new char[456];
while(br.read(line) > 0){
StringBuilder input = new StringBuilder(new String(line));
if(batchCounter>0){
int detailFileId = interfaceFileSequence();
sql.append(initSql+"(" +
detailFileId + "," + interfaceHeaderId + ", SYSDATE," +
interfaceRunId + "," + isSpace(input.substring(0, 2).trim()) + "," + "TO_DATE("+isSpace(input.substring(2, 12).trim())+",'YYYY-MM-DD')" +","+isSpace(input.substring(12, 22).trim()) + "," +
Double.parseDouble(input.substring(22, 35)+ "." + input.substring(35, 37)) + ", " +
Double.parseDouble(input.substring(22, 35)+ "." + input.substring(35, 37)) + ", " +
isSpace(input.substring(38, 44).trim()) + ","+isSpace(input.substring(38, 44).trim())+"," +isSpace(input.substring(38, 44).trim())+"," + isSpace(input.substring(44, 54).trim())+","+
isSpace(input.substring(54, 60).trim()) + "," + isSpace(input.substring(60, 68).trim()) + "," + isSpace(input.substring(68, 83).trim()) + "," +
isSpace(input.substring(83, 89).trim()) + "," + isSpace(input.substring(89, 94).trim()) + "," +
isSpace(input.substring(94, 102).trim()) + "," +
isSpace(input.substring(102, 103).trim()) + ","+"TO_DATE("+isSpace(input.substring(103,113).trim())+",'YYYY-MM-DD')"+"," +isSpace(input.substring(113, 125).trim()) + "," + isSpace(input.substring(125, 128).trim()) + "," +
isSpace(input.substring(131, 133).trim()) + "," + isSpace(input.substring(133, 135).trim()) + "," + isSpace(input.substring(135, 136).trim()) + "," +
isSpace(input.substring(136, 137).trim()) + "," + isSpace(input.substring(137, 142).trim()) + "," + isSpace(input.substring(142, 147).trim()) + "," +
isSpace(input.substring(147, 148).trim()) + "," + isSpace(input.substring(149, 159).trim()) + "," +
isSpace(input.substring(159, 160).trim()) + "," + isSpace(input.substring(160, 175).trim()) + "," + isSpace(input.substring(160, 175).trim()) + "," +
isSpace(input.substring(190, 220).trim()) +"," +"TO_DATE("+isSpace(input.substring(216, 220)+"-"+input.substring(220, 222)+"-"+input.substring(222, 224))+",'YYYY-MM-DD')"+","+
"TO_DATE("+isSpace(input.substring(216, 220)+"-"+input.substring(220, 222)+"-"+input.substring(222, 224))+",'YYYY-MM-DD')"+","+ isSpace(input.substring(226,227).trim()) + "," + isSpace(input.substring(231,236).trim()) + "," +
isSpace(input.substring(242, 245).trim()) + "," + isSpace(input.substring(245,275).trim()) + "," + isSpace(input.substring(275,280).trim()) + "," +
isSpace(input.substring(280, 290).trim()) + "," + isSpace(input.substring(290,293).trim()) + "," + isSpace(input.substring(293,303).trim()) + "," +
isSpace(input.substring(303, 314).trim()) + "," +
isSpace(input.substring(313,316).trim()) + //need check
"," + isSpace(input.substring(317,337).trim()) + "," +
isSpace(input.substring(337, 422).trim()) +
"," + isSpace(input.substring(422,433).trim()) + "," + isSpace(input.substring(433,443).trim())+","+isSpace(input.substring(22, 39).trim())+
")");
sql.append('\n');
}
/*if (batchCounter % 500 == 0) {
System.out.println("sql:::::::::::"+sql);
int executeUpdate = em.createNativeQuery(sql.toString()).executeUpdate();
System.out.println("executeUpdateexecu:::"+executeUpdate);
em.flush();
insertionCounter += executeUpdate;
System.out.println("insertionCounter::::"+insertionCounter);
sql.setLength(0);
System.out.println("SQL");
System.out.println("initSql"+initSql);
sql.append(initSql);
}*/
batchCounter++;
}
sql.append(" SELECT * FROM dual");
int executeUpdate = em.createNativeQuery(sql.toString()).executeUpdate();
em.flush();
insertionCounter += executeUpdate;
System.out.println("Check Rows in file::"+(batchCounter-1)+" Insertion counter::"+insertionCounter);
if((batchCounter-1)==insertionCounter){
detailFileObj = new DetailFileObject(FileName, "DETAIL", (batchCounter-1), "SUCCESS");
}
else {
detailFileObj = new DetailFileObject(FileName, "DETAIL", (batchCounter-1), "FAILED");
}
} catch (IOException e) {
e.printStackTrace();
}
But once I am running the code, if there are 40-50 lines, it is working fine.But it is more than that I am getting exception. Can anyone share me proper approach along with running code, so that I can use it.
Thanks
First, DO NOT use string concatenation to build a SQL statement with text values from outside. It leaves you susceptible to SQL Injection attacks, and may cause SQL syntax errors. Use a PreparedStatement with ? parameter markers instead.
Second, if you're inserting a lot of records, use JDBC batching.
Here is an example of how you would use it:
String sql = "INSERT INTO MyTable" +
" ( Col1, Col2, Col3, Col4, Col5, Col6, Col7 )" +
" VALUES (?,?,SYSDATE,?,?,?,?)";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
char[] line = new char[456];
int batchSize = 0;
while (br.read(line) > 0) {
String input = new String(line);
int detailFileId = interfaceFileSequence();
stmt.setInt (1, detailFileId);
stmt.setInt (2, interfaceHeaderId);
stmt.setInt (3, interfaceRunId);
stmt.setString(4, toString(input.substring(0, 2)));
stmt.setDate (5, toDate(input.substring(2, 12)));
stmt.setString(6, toString(input.substring(12, 22)));
// ...
stmt.addBatch();
if (++batchSize == 1000) {
stmt.executeBatch();
batchSize = 0;
}
}
if (batchSize != 0) {
stmt.executeBatch();
}
} catch (IOException e) {
e.printStackTrace();
}
The above code uses the following helper methods to keep code DRY:
private static String toString(String text) {
String trimmed = text.trim();
return (trimmed.isEmpty() ? null : trimmed);
}
private static java.sql.Date toDate(String text) {
String trimmed = text.trim();
return (trimmed.isEmpty() ? null : java.sql.Date.valueOf(LocalDate.parse(trimmed)));
}
I've written a method that searches the database to find matching lecturers depending on modules. However, when I run this, it saves the same name for all three!
Here is the method:
public List<tableModules> getStudentsLecturers(String mod1, String mod2, String mod3) {
List<tableModules> studentModuleLecturer = new ArrayList<tableModules>();
// Select All Query to find lecturers depending on modules
Log.d("Lecturers", mod1);
Log.d("Lecturers", mod2);
Log.d("Lecturers", mod3);
String selectQuery = "SELECT DISTINCT " + Module_Lecturer + " FROM " + Table2 + " WHERE " + Module_Name + " = \'" + mod1 + "\' OR \'" + mod2 + "\' OR \'" + mod3 + "\'";
Log.d("1", "1");
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
tableModules moduleLecturers = new tableModules();
moduleLecturers.modulelecturer = cursor.getString(0);
studentModuleLecturer.add(moduleLecturers);
} while (cursor.moveToNext());
}
// return lecture list
return studentModuleLecturer;
}
Which is then called here in MainActivity.java
List<tableModules> lecturers = db.getStudentsLecturers(mod1, mod2, mod3);
if (!lecturers.isEmpty())
{
for (tableModules session: lecturers)
{
Editor editor = preferences.edit();
//Save lecturers to list
for (int i=0; i < lecturers.size(); i++) {
if (counter == 0)
{
lecturer1 = session.modulelecturer.toString();
editor.putString("lec1", lecturer1);
Log.d("Lecs", "1");
editor.commit();
counter++;
}
if (counter == 1)
{
lecturer2 = session.modulelecturer.toString();
editor.putString("lec2", lecturer2);
Log.d("Lecs", "2");
editor.commit();
counter++;
}
if (counter == 2)
{
lecturer3 = session.modulelecturer.toString();
editor.putString("lec3", lecturer3);
Log.d("Lecs", "3");
editor.commit();
counter++;
}
else
{
Log.d("Lecs", "ERROR");
}
}
I get that I'm saving the same "session.modulelecturer.toString();" to each, but I can't figure out how to alter the SQL method to select all three lecturers for all three seperate modules.
Try replacing
" WHERE " + Module_Name + " = \'" + mod1 + "\' OR \'" + mod2 + "\' OR \'" + mod3 + "\'";
with
" WHERE " + Module_Name + " = '" + mod1 + "' OR " + Module_Name + " = '" + mod2 + "' OR " + Module_Name + " = '" + mod3 + "'";
In practice, you can't say
WHERE ModuleName = 'This' OR 'That'
but you can say
WHERE ModuleName = 'This' OR ModuleName = 'That'
I know it's a drag to rewrite the column name for each possible value, but it's how it works in SQL.
Alternatively, you can write a more compact form:
WHERE ModuleName IN ('This', 'That', '...')
So you query can become:
" WHERE " + Module_Name + " IN ('" + mod1 + "', '" + mod2 + "', '" + mod3 + "')";
This is a stock management system and I have a problem with updating part in good received note. When we purchase goods, we get a good received note, so when we get the items the number of items has to be updated (has to be added to the remaining goods) according to the item code.
According to the following code data from GRN will be extracted and will be saved in GRN1 and GRN2 tables. There's another table called Item_Supplier, when we receive goods Stock in hand field in Item_Supplier table has to updated according to the item_Id as well.
Problem is following code does not work.
Connection ss = Class_DB.myconnection();
Statement st = ss.createStatement();
-
ResultSet rs = st.executeQuery("select stock_in_hand from item_supplier where item_ID =('" + TF_GRN_ITEMID.getText() + "')");
grniid = TF_GRN_NO_OF_ITEM.getText();
while (rs.next()) {
nit = rs.getString("stock_in_hand");
}
sumn = grniid + nit;
st.executeUpdate("insert into grn1 values('" + TF_GRN_GRNNO.getText() + "','" + TF_GRN_SUPPLIERID.getText() + "','" + TF_GRN_AMOUNT.getText() + "','" + TF_GRN_DATE.getText() + "')");
st.executeUpdate("insert into grn2 values('" + TF_GRN_GRNNO.getText() + "','" + TF_GRN_ITEMID.getText() + "','" + TF_GRN_EXP_DATE.getText() + "','" + TF_GRN_TAX.getText() + "','" + TF_GRN_NO_OF_ITEM.getText() + "','" + TF_GRN_GAMOUNT.getText() + "','" + TF_GRN_NAMOUNT.getText() + "','" + TF_GRN_QTY.getText() + "','" + TF_GRN_UNIT.getText() + "','" + TF_GRN_FREE.getText() + "','" + TF_GRN_DIS.getText() + "')");
st.executeUpdate("update item_supplier set stock_in_hand='" + sumn + "' where item_ID='" + TF_GRN_ITEMID.getText() + "'");
JOptionPane.showMessageDialog(null, "Data Saved");
Please help.
I have a method getstaffinfo, which has 3 parameter (var_1, connection, filewriter fw), the var_1 value is read from a text file. So the method will be called as many times based on all the var_1 value passed from text file . approx ( 15000)
public static String getstaffid(String var_1, Connection connection,
FileWriter fw) throws SQLException, Exception
// Create a statement
{
String record = null;
ResultSet rs = null;
Statement stmt = connection.createStatement();
boolean empty = true;
try {
rs = stmt
.executeQuery("select username, firstname, lastname, middlename, street, city, stateorprovince, ziporpostalcode, countryorregion, fax, phone, extension, mobile, pager, title, primaryemail, secondaryemail, officename, description, comments, suspendeddate, userdata, employeeid, createuser, updateuser, createdate, updatedate, employeetype, servicedeskticketnumber, startdate, enddate, manager, businessapprover, technicalapprover, delegate, location, jobcodes, customproperty1, customproperty2, customproperty3, customproperty4, customproperty5, customproperty6, customproperty7, customproperty8, customproperty9, customproperty10 from globalusers where username = '"+ var_1 + "'");
ResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
ArrayList<String> records = new ArrayList<String>();
while (rs.next()) {
empty = false;
//record = rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6) + " " + rs.getString(7) + " " + rs.getString(8) + " " + rs.getString(9) + " " + rs.getString(10) + " " + rs.getString(11) + " " + rs.getString(12) + " " + rs.getString(13) + " " + rs.getString(14) + " " + rs.getString(15) + " " + rs.getString(16) + " " + rs.getString(17) + " " + rs.getString(18) + " " + rs.getString(19) + " " + rs.getString(20) + " " + rs.getString(21) + " " + rs.getString(22) + " " + rs.getString(23) + " " + rs.getString(24) + " " + rs.getString(25) + " " + rs.getString(26) + " " + rs.getString(27) + " " + rs.getString(28) + " " + rs.getString(29) + " " + rs.getString(30) + " " + rs.getString(31) + " " + rs.getString(32) + " " + rs.getString(33) + " " + rs.getString(34) + " " + rs.getString(35) + " " + rs.getString(36) + " " + rs.getString(37) + " " + rs.getString(38) + " " + rs.getString(39) + " " + rs.getString(40) + " " + rs.getString(41) + " " + rs.getString(42) + " " + rs.getString(43) + " " + rs.getString(44) + " " + rs.getString(45) + " " + rs.getString(46) + " " + rs.getString(47);
for (int i = 1; i <= columns; i++) {
String value = rs.getString(i);
records.add(value);
}
for (int j = 0; j < records.size(); j++) {
record = records.get(j) + ",";
}
fw.append(record);
}
/*fw.append(rs.getString(1));
fw.append(',');
fw.append(rs.getString(2));
fw.append(',');
fw.append(rs.getString(3));
fw.append('\n'); */
} finally {
fw.flush();
rs.close();
stmt.close();
}
return record;
}
As you can see, am executing a query for 47 values, which could be null or it can have some value.
Then i iterate through this 47 column, take the value and store it to an array list. Then i iterate the array list and write all the values to the string record with comma seperated value. Which is written to a csv file.
But it does not work fine. Any inputs would be appreciated...
You may have already solved the problem. Just let you know that I tried to use your code just now and found the issue was here:
record = records.get(j) + ",";
You should use something like this:
record = record + records.get(j) + ",";
Also change String to StringBuffer will improve the performance.
You didn't write the exact problem you face, but there is one for sure: you never write a line break into the file, so all data gets in one line.
while (rs.next()) {
... // your code, with the for loops
fw.append(record); //writing out the line, from your code
fw.append("\r\n"); //line break -- add this line
} //this is the end of the "while(rs.next())" loop
...
I am having a small problem while I try to insert some data in my database (MS - SQL).
I am using this code (I just copy-paste all of it, so someone might understand smth that I don't)
try
{
Connection connection = null;
Statement Statement = null;
ResultSet ResultSet = null;
String query = "";
// jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
String host = "jdbc:sqlserver://server;databaseName=db";
String username = "user";
String password = "pass";
Statement = connection.createStatement();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
DateFormat dateFormat1 = new SimpleDateFormat("dd.MM.yyyy");
Calendar cal1 = Calendar.getInstance();
for (int k = 0; k < idArray.length ; k ++ )
{
query = "INSERT INTO Companies (ID,Company,Company2,Company3,Country,ZIP,City,Street," +
"Phone,Fax,Email,Internet,CustomerNo,AccountMngr,Icon,AddressSource," +
"UserDefined1,UserDefined2,CreatedOn,CreatedBy,ColectedInformation) " +
" VALUES ('" + UUID.randomUUID() + "','" + company_nameArray[k]
+ "','" + company_name2Array[k] + "','" + company_name3Array[k] + "','DE','"
+ zipArray[k] + "','" + cityArray[k] + "','" + streetArray[k] + "','"
+ phone_Array[k] + "','" + faxArray[k] + "','" + emailArray[k] + "','"
+ internetArray[k] + "','" + customer_noArray[k]
+ "','d','131','60','Baufinder Import','Import Datum "
+ dateFormat1.format(cal1.getTime()) + "','"
+ dateFormat1.format(cal1.getTime()) + "','d','"
+ "cxcxvcx" +
"')";
ResultSet = Statement.executeQuery(query);
}
connection.close();
}
catch(NullPointerException e)
{
System.out.println("NullPointerException");
}
catch ( SQLException err )
{
System.out.println( "SQL Exception:" ) ;
// Loop through the SQL Exceptions
while( err != null )
{
System.out.println( "State : " + err.getSQLState() ) ;
System.out.println( "Message: " + err.getMessage() ) ;
System.out.println( "Error : " + err.getErrorCode() ) ;
err = err.getNextException() ;
}
}
catch( Exception e )
{
System.out.println( "There is a problem with " + e ) ;
}
}
and I am getting this error:
SQL Exception: State : null
Message: There was no result set returned by the statement.
Error : 0
I don't understand the problem with the result test. I have been using it a lot, since I try to read the data from another database and now I try to insert them to another.
Furthermore, all of these tables do not include null values.
Thank you in advance:)
Use Statement#executeUpdate(String) instead of Statement#execute(query);
for (int k = 0; k < idArray.length ; k ++ )
{
query = "INSERT INTO Companies (ID,Company,Company2,Company3,Country,ZIP,City,Street," +
"Phone,Fax,Email,Internet,CustomerNo,AccountMngr,Icon,AddressSource," +
"UserDefined1,UserDefined2,CreatedOn,CreatedBy,ColectedInformation) " +
" VALUES ('" + UUID.randomUUID() + "','" + company_nameArray[k]
+ "','" + company_name2Array[k] + "','" + company_name3Array[k] + "','DE','"
+ zipArray[k] + "','" + cityArray[k] + "','" + streetArray[k] + "','"
+ phone_Array[k] + "','" + faxArray[k] + "','" + emailArray[k] + "','"
+ internetArray[k] + "','" + customer_noArray[k]
+ "','d','131','60','Baufinder Import','Import Datum "
+ dateFormat1.format(cal1.getTime()) + "','"
+ dateFormat1.format(cal1.getTime()) + "','d','"
+ "cxcxvcx" +
"')";
int updatedRowCount = Statement.executeUpdate(query);
}
Notes:
Please consider using PreparedStatement to prevent possibility of SQL Injection if some data directly input by User.
Try to use batch insert if you need to improve performance of inserting.