Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:08:42+00:00 2026-06-10T10:08:42+00:00

I am working on a desktop application with Java Swing and save data on

  • 0

I am working on a desktop application with Java Swing and save data on a MySQL database in arabic language with using UTF-8.

When I run the application from Eclipse everything work well but when I finish and I export my work to a runnable jar using Eclipse export, nothing related to the database works.

  • Login doesn’t work
  • When I try to save date to my database in Arabic I get ?????? in the database

However, as I mentioned earlier, everything work correctly when I run it from Eclipse. Can any one help me, I must deliver my work

This is a sample of my work:

This is how I connect connect my database :

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";

This is the code for 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();
            } 
        }
    }   
}

Resulting MySQL variables using this cmd :SHOW VARIABLES LIKE ‘c%’;
abd every thins is uts8

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:08:43+00:00Added an answer on June 10, 2026 at 10:08 am

    First, you should never convert a String to bytes using an unspecified charset (here you are using the platform default, which could change):

    passwordlogin.getBytes()
    

    Since this is for the bytes you are going to hash, which charset you use doesn’t really matter as long as it is consistent. something like passwordlogin.getBytes("UTF-8") would seem reasonable.

    Also, this is certainly a problematic bit of code:

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

    it seems to imply that you have a characterset breakdown somewhere.

    Lastly, how are you running your jar? Are you specifying a charset on the command line (e.g. java -Dfile.encoding="UTF-8" ...).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on the Java desktop application using Swing. As the application is
I'm working on converting a very simple java desktop application to run in java
I am writing a Desktop GUI application in Clojure using Java Swing. Normally when
I am working in a desktop application for windows using Java. In my application,
I am working in a desktop application for windows using Java. In my application,
I developed a small desktop application in Netbeans using Java. The application is working
I'm currently working on a project that is building a java-based desktop application to
I'm working on a java applet/desktop application. It runs directly on the desktop, and
I am working on a desktop application which uses JavaDB. I am using NetBeans
I am working on a simple desktop java application. I would like to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.