fail to insert non-english characters to database using crontab to run the program

允我心安 提交于 2019-12-24 17:15:16

问题


I use crontab to run some programs automatically everyday. since 7 days ago whenever I run one of program automatically(every day at 3 am) to insert some strings(contains numbers and English and non-English letters) to a table in database, only numbers and english characters(ASCII chars) insert to database but before that time it was working fine. but when I run the program by myself,the other characters will insert to table,too.

on the other hand, I run another program with crontab at 2 am and that also inserts some strings to the same database(but different table) but it works fine and all characters(English and Non-English) insert to Database.

Server OS is centOS 6.3 minimal and I'm using MySql Database 5.1.61 and my database collation is : utf8-utf8_general_csi. In both programs i use java and its jdbc library.

I am only doubted with crontab. I'll be thankful for any help.

EDIT:
here's the crontab i made:

0 2 * * * java -jar file.jar arg1 arg2 arg3
4 15 * * * java -jar file3.jar arg1 arg2 args3
0 3 * * * java -jar file2.jar arg1 arg2 arg3

.the programs that run at 2 at 3 have the same functionality. but when running the one at 3(file2.jar), non-English chars doesn't inserts.

And here's a part of the code that i insert to DB:

stmt = (Statement) con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE) ;
            stmt.executeUpdate("set character_set_results=utf8"); 
            stmt.executeUpdate("set character_set_filesystem=utf8");
   try
   {
       rs.moveToInsertRow();
       rs.updateString("f1", str1);
       rs.updateString("f2", str2);
       rs.updateFloat("f3", fl1));

       rs.insertRow();

   }
   catch(Exception ex)
   {
   }

回答1:


I couldn't find anyway to fix the problem so I wrote a schedular program that runs the application and it works fine!!!

But I'm still confused why crontab makes that problem or what I did that program doesn't work fine!!!



来源:https://stackoverflow.com/questions/19652588/fail-to-insert-non-english-characters-to-database-using-crontab-to-run-the-progr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!