5

を使用してデスクトップアプリケーションに取り組んでおり、アラビア語でデータベースにJava Swingデータを保存しています。MySQLUTF-8

すべてからアプリケーションを実行するとEclipseうまくいきますが、終了して作業をrunnable jarusingにエクスポートEclipse exportすると、データベースに関連するものは何も機能しません。

  • ログインが機能しない
  • データベースに日付を保存しようとすると、データベースにArabic入り??????ます

ただし、前述したように、から実行するとすべて正常に動作しEclipseます。誰か助けてくれませんか、仕事を届けなければなりません

これは私の作品のサンプルです:

これは、データベースに接続する方法です。

static Connection conn = null;
static String url      = "jdbc:mysql://localhost:3306/";
static String dbName   = "gestiondestock";
static String driver   = "com.mysql.jdbc.Driver";
static String userName = "root"; 
static String password = "";
static String unicode= "?useUnicode=yes&characterEncoding=UTF-8";

これはのコードですbuttonLogin ActionPerformed:

private void buttonLogin_ActionPerformed(ActionEvent e) {
    if(textField.getText().equals("") || passwordField.getText().equals(""))
    {
       jd =new JDialog();
        jd.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        jd.setTitle("الرجاء ملء الفراغ");
        jd.setVisible(true);
        jd.setLocationRelativeTo(null);
        jd.setSize(400,200);
        jd.setContentPane(buildpp());   
    }
    else{
        if(textField.getText().equals("Adel91") || passwordField.getText().equals("Adel91"))
        {
            CardLayout cardLayout = (CardLayout) contentPane.getLayout();
            cardLayout.show(contentPane, "Panel_Home");
        }
        else{
            try{
                String usernamena = new String(textField.getText());
                String passwordlogin = new String(passwordField.getText());

                MessageDigest mdEnc4 = MessageDigest.getInstance("MD5");

                mdEnc4.update(passwordlogin.getBytes(), 0, passwordlogin.length());
                String passwordlogindmd5 = new BigInteger(1, mdEnc4.digest()).toString(16); // Encrypted 

                try{
                    Class.forName(driver).newInstance();
                    conn = DriverManager.getConnection(url+dbName+unicode,userName,password);
                    Statement st = conn.createStatement();

                    ResultSet res = st.executeQuery("SELECT username,password FROM client ");

                    String user = null;
                    String pass = null;

                    if(res.next()) {
                        user = new String( res.getBytes(1), "UTF-8");
                        pass =  new String( res.getBytes(2), "UTF-8");
                    }

                    if(usernamena.equals(user)&&passwordlogindmd5.equals(pass)){
                        CardLayout cardLayout = (CardLayout) contentPane.getLayout();
                        cardLayout.show(contentPane, "Panel_Home");
                    }
                    else{
                        jd =new JDialog();
                        jd.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
                        jd.setTitle("كلمة المرور والإسم غير مناسبان");
                        jd.setVisible(true);
                        jd.setLocationRelativeTo(null);
                        jd.setSize(430,200);
                        jd.setContentPane(buildwronglogin());
                    }
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
            } catch (NoSuchAlgorithmException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } 
        }
    }   
}

このコマンドを使用して得られる MySQL 変数:SHOW VARIABLES LIKE 'c%'; アブド・エヴリ・シンズはuts8です

ここに画像の説明を入力

4

2 に答える 2

5

まず、指定されていない文字セットを使用して文字列をバイトに変換しないでください(ここではプラットフォームのデフォルトを使用していますが、変更される可能性があります)。

passwordlogin.getBytes()

これはハッシュするバイト用であるため、一貫している限り、どの文字セットを使用するかは実際には重要ではありません。のようなものpasswordlogin.getBytes("UTF-8")は合理的に見えるでしょう。

また、これは確かに問題のあるコードです。

                if(res.next()) {
                    user = new String( res.getBytes(1), "UTF-8");
                    pass =  new String( res.getBytes(2), "UTF-8");
                }

どこかにキャラクターセットの内訳があることを意味しているようです。

最後に、jarファイルをどのように実行していますか?コマンドラインで文字セットを指定していますか(例java -Dfile.encoding="UTF-8" ...)。

于 2012-08-28T01:19:56.227 に答える
3

で起動しますjava -Dfile.encoding="UTF-8" -jar JarFile.jar

于 2016-05-20T10:13:48.220 に答える