无法使用crontab运行程序将非英语字符插入数据库 [英] fail to insert non-english characters to database using crontab to run the program

查看:110
本文介绍了无法使用crontab运行程序将非英语字符插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天使用crontab自动运行一些程序. 从7天前开始,每当我自动运行一个程序(每天凌晨3点)向数据库表中插入一些字符串(包含数字,英文和非英文字母)时,仅数字和英文字符(ASCII字符)插入到数据库,但在此之前运行良好. 但是当我自己运行程序时,其他字符也会插入表格中.

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.

另一方面,我在凌晨2点运行了一个带有crontab的程序,该程序还将一些字符串插入到同一数据库(但不同的表)中,但是它可以正常工作,并且所有字符(英语和非英语)都插入到数据库中.

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.

服务器操作系统最低为centOS 6.3,我使用的是MySql Database 5.1.61,我的数据库排序规则是:utf8-utf8_general_csi. 在这两个程序中,我都使用Java及其jdbc库.

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.

我只是对crontab感到怀疑. 感谢您的帮助.

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


这是我制作的crontab:


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

.以2 at 3运行的程序具有相同的功能.但是在3(file2.jar)运行一个时,不会插入非英语字符.

.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)
   {
   }

推荐答案

我仍然找不到解决问题的方法,所以我编写了一个时间表程序来运行该应用程序,并且运行良好!!

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

但是我仍然感到困惑,为什么crontab会导致该问题,或者我所做的该程序无法正常工作!!

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

这篇关于无法使用crontab运行程序将非英语字符插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆