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

  • Home
  • SEARCH
  • 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 5972931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:43:40+00:00 2026-05-22T20:43:40+00:00

I am crawling webpages to MySQL database using Java. These webpages are in various

  • 0

I am crawling webpages to MySQL database using Java.

These webpages are in various encoding(e.g. GBK, UTF8 …) and may contain none ASCII characters, however, I managed to detect each page’s encoding and get the readable string(readable string means it displays the same in Eclipse console as in Web Browser).

I get webpage encoding, defaults to UTF-8 if not found, from <meta> tag.
See the following snippet:

InputStream is = hconn.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int b = -1;
while (-1 != (b = is.read())) {
    baos.write((byte) b);
}

String charset = "UTF-8";
Document doc = Jsoup.parse(baos.toString());
Elements metas = doc.select("meta[http-equiv=Content-Type]");

Pattern p = Pattern.compile("charset=([0-9a-zA-Z_\\-]+)");
Matcher m;

for (Element meta : metas) {
    m = p.matcher(meta.toString());
    if (m.find())
        charset = m.group(1);
}

String str = new String(baos.toByteArray(), charset);

Then, I store it to MySQL. The MySQL connection url is jdbc:mysql://localhost:3306/db?characterEncoding=gbk, and the column to store text to is of GBK encoding.

Things happened that strings well displayed in Eclipse console turned out to be none recognizable sequence in MySQL and sometimes may raise SQLException. Observationally, none GBK strings will go wrong.

I think converting Non-GBK strings to GBK will work, but how to?
And are there any work around approaches? My final goal is construct an inverted index.

Answers to encoding converting is preferred.

Any help will be grateful. Thanks in advance.


Add:

Create table SQL:

CREATE TABLE `indexer`.`pages` (
  `content` TEXT CHARACTER SET gbk COLLATE gbk_chinese_ci,
  `url` VARCHAR(512) NOT NULL,
  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
)
ENGINE = InnoDB;

Error Message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'é”??μ¢Wé”??μ?é”??μ—é”??–¤??·DPIyé”????é”??–¤??·é”????0")Sé”????<é”????cé”??–¤??' at line 1

  • 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-05-22T20:43:41+00:00Added an answer on May 22, 2026 at 8:43 pm

    Java will represent the string correctly internally which is shown by the Eclipse console. You should be able to connect to the database using UTF8 and store the data in a UTF8 encoded column. If you want the column to be GBK, I would still connect using UTF8. If this doesn’t work, it would be helpful if you can post your CREATE TABLE statement and the error messages you were getting before.

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

Sidebar

Related Questions

I need to access a lucene index ( created by crawling several webpages using
I'm crawling a website using php. As I don't know much about turning php
When crawling on webpages I need to be careful as to not make too
For the past month I've been using Scrapy for a web crawling project I've
I'm using mechanize (which uses clientform) for some web crawling in python and since
A web-bot crawling your site and using bandwdith resources. Bots are numerous and for
I am working on a crawling script in PHP. I am using PHP Simple
I need xml file for indexing my website for google crawling. I'm using some
I'm crawling webpages from different websites and they have varied encodings. A sample of
I am currently thinking how to best store web-crawling results in a database. In

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.