To save an Arabic text into your MySql database table, you first check the table column is set to "utf8" or not. If not, switch to table structure tab of phpmyadmin and click change under action column, here you will see a column "Collation" and choose "utf8_general_ci" from utf8 group and save.
In Java, we can connect to our database(MySQL) with JDBC(Java Database Connectivity) through the Java code. JDBC is one of the standard APIs for database connectivity, using it we can easily run our query, statement, and also fetch data from the database.
MySQL provides connectivity for client applications developed in the Java programming language with MySQL Connector/J. Connector/J implements the Java Database Connectivity (JDBC) API, as well as a number of value-adding extensions of it. It also supports the new X DevAPI.
I have a java application, want to insert arabic words to mysql database, my code looks like
Connection con = null;
String url = "jdbc:mysql://localhost/";
String db = "students";
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
Statement st = con.createStatement();
String name = new String(txtName.getText().getBytes(), "UTF-8");
int val = st.executeUpdate("insert into student(name, roll) VALUES('"+name+"','"+txtRoll.getText()+"')");
} catch (Exception ex) {
ex.printStackTrace();
}
But it only insert '??????'. what can i do now?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With