我正在开发一个桌面应用程序Java
Swing
并将数据保存在MySQL
阿拉伯语数据库,使用UTF-8
.
当我运行应用程序时Eclipse
一切都运行良好,但是当我完成并将我的工作导出到runnable jar
using Eclipse
export
,与数据库相关的任何事情都不起作用。
- 登录不起作用
- 当我尝试将日期保存到我的数据库时
Arabic
I get ??????
在数据库中
但是,正如我之前提到的,当我从以下位置运行它时,一切正常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