Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert arabic word to mysql database using java

Tags:

People also ask

How do I get MySQL to accept Arabic?

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.

How do I connect MySQL database and Java?

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.

Does MySQL support Java?

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?