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 8252443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:34:05+00:00 2026-06-08T00:34:05+00:00

I want to store some Hindi words in a MySQL database. For that I

  • 0

I want to store some Hindi words in a MySQL database. For that I wrote a web crawler. I am able to read those words successfully from HTML page and display them in the NetBeans console. But when I insert them in MySQL they change to ???????. Also if I insert the same words using SQL query in PHPMyAdmin itself, they get stored properly.

I have searched Google and various forums a lot and have taken proper precautions in handling Unicode in most places. Do we have to mention explicitly in the SQL statements (JDBC) if entering Unicode?

Here is my whole code.

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.*;

public class TestDataParsing2 {
  public int counter = 1;
  private String ID = "";
  private String title = "";
  private String owner = "";
  private String s="";

  private Connection conn = null;
  private String url = "jdbc:mysql://localhost:3306";
  private String dbName = "/hindi-eng";
  private String driver = "com.mysql.jdbc.Driver";
  private String userName = "root";
  private String password = "";
  private String TABLE = "dict";

private void initdb(){
  try {
    Class.forName(driver).newInstance();
    conn = DriverManager.getConnection(url+dbName,userName,password);
  } catch (Exception e) {
    e.printStackTrace();
  }
}

private void closedb(){
  try {
    conn.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}
public void process(String content){
  try{
    BufferedReader reader =  new BufferedReader(new StringReader(content));
    String text = "";
    boolean start1 = false;
    boolean start2 = false;
    while (( text = reader.readLine()) != null) {
      if(text.contains("\"a")) {
        System.out.println("______________________________________________________________");
        String id = getID(text);
        this.ID = id;
        String title = getTitle(text);
        this.title = title;
        String owner = getOwner(text);
        this.owner = owner;
        start1 = true;
      }
      if(start1 && start2) {
        String s = getS(text);
        this.s = s;
        counter++;
        insert();
        start2=false;
        start1= false;
      }
      if(start1) {
        start2= true;
      }
    }
  }catch(Exception e){
    System.out.println(e);
  }
}

public void insert(){
  String insertString = "INSERT INTO " + TABLE + " VALUES (" + this.counter + ",'" +
    this.ID + "','" + this.title + "','" + this.owner + "','" + this.s + "')";
  System.out.println(insertString);
  try {
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(insertString);
    stmt.close();
  } catch(Exception e) {
    System.out.println(e);
  }
}

public String getID(String text){
  String id = "";
  id = text.substring(text.indexOf("\"")+1, text.indexOf("\","));
  return id;
}

public String getTitle(String text){
  String title = "";
  title = text.substring(text.indexOf(",\"")+2, text.indexOf("\",\"1."));
  return title;
}

public String getOwner(String text){
  try{
    String owner = "";
    owner = text.substring(text.indexOf("\",\"1.")+5, text.indexOf("\"<br>"));
    int i;
    for(i=0;i<owner.length();i++) {
      String fifthChar = "\u00AE";
      int codePoint = owner.codePointAt(i);
    }
    return owner;
  } catch(Exception e) {
    System.out.println(e);
    System.out.println("eeee");
  }
  return owner;
}

public String getS(String text){
  String s = "";
  s = text.substring(0, text.indexOf("<br>"));
  return s;
}

public String download(String path) {
  String result = "";
  try {
    URL url = new URL(path);
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    InputStream in = null;
    in = url.openStream();
    String content = pipe(in,"utf-8");
    result = content;
  } catch (Exception e) {
    e.printStackTrace();
  }
  return result;
}

public String pipe(InputStream in,String charset) throws IOException {
  StringBuffer s = new StringBuffer();
  if(charset==null||"".equals(charset)){
    charset="utf-8";
  }
  String rLine = null;
  BufferedReader bReader = new BufferedReader(new InputStreamReader(in,"UTF-8"));
  FileOutputStream("C:\\Research\\MiningSoftwareRepositories\\Traceability-Link-Recovery\\EXPERIMENTS\\BR\\"
    + bugid + ".txt");
  while ( (rLine = bReader.readLine()) != null) {
    String tmp_rLine = rLine;
    s.append(tmp_rLine+"\n");
  }
  tmp_rLine = null;
}
  in.close();
  return s.toString();
}

public static void main(String[] args) {
  TestDataParsing2 tdp = new TestDataParsing2();
  tdp.initdb();
  System.out.println("process started");
  String urlPath = "file:///C:/Users/Abhinav/Downloads/Compressed/eng-hindi-dict-utf8/sa.htm";
  String content = tdp.download(urlPath);
  tdp.process(content);
  tdp.closedb();
}

Also when I add “?useUnicode=yes&characterEncoding=UTF-8” to the conn_url I get the following errors which were not coming without it.

java.sql.SQLException: Unsupported character encoding ‘UTF-8/hindi-eng’.
process started
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:574)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:719)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:704)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2573)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2713)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2663)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1599)
at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3928)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3473)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2445)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at TestDataParsing2.initdb(TestDataParsing2.java:29)
at TestDataParsing2.main(TestDataParsing2.java:239)


INSERT INTO dict VALUES (2,’a’,’Art’,’एक’,’I bought a pen.’)
java.lang.NullPointerException
__________________________________
INSERT INTO dict VALUES (3,’aback’,’Adv’,’पीछे/हतप्रभ’,’I was somewhat taken aback by his rudeness.’)
java.lang.NullPointerException

  • 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-08T00:34:07+00:00Added an answer on June 8, 2026 at 12:34 am

    You don’t specify the database connection encoding, so the server default encoding gets used. It looks like the server is not configured to use UTF-8.

    You can either set the server encoding to UTF-8, or set the characterEncoding property on the connection:

    conn = DriverManager.getConnection(url+dbName+"?characterEncoding=UTF-8",userName,password);
    

    Remember that the syntax of the connection url is “jdbc:mysql://host:port/database?option1=value1&option2=value2&…”.

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

Sidebar

Related Questions

I store some data in MySQL and want to filter out rows that match
I want to store some dates into MySQL but those dates are without years
I want store some article into database. I use php and mysql. Whether have
I want to store some value from SQLite database in my buffer, but the
I want to use session object in my web app.I want to store some
Is this possible? Situation is that I want to store some XML in my
I want to store some confidential values (such as database connection strings, some passwords)
I want to store some objects and then be able to retrieve them later
We want to store some meta-information about the commit in an external database. During
I want to store some coordinates on a text files that correspond to an

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.