Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以在不转换为Unicode的情况下将印地语字符传递到mysql数据库?_Mysql_Jsp_Encoding_Utf 8_Itext - Fatal编程技术网

是否可以在不转换为Unicode的情况下将印地语字符传递到mysql数据库?

是否可以在不转换为Unicode的情况下将印地语字符传递到mysql数据库?,mysql,jsp,encoding,utf-8,itext,Mysql,Jsp,Encoding,Utf 8,Itext,正如我的问题所说,是否可以直接将印地语字符保存到数据库而不进行编码त५。我需要将名称保存在mysql数据库中 我问这个问题的原因是我尝试使用UTF-8编码,甚至在表中,我创建了这个 CREATE TABLE `hindi` ( `data` varchar(200) COLLATE utf8_unicode_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 但它给了我तñ

正如我的问题所说,是否可以直接将印地语字符保存到数据库而不进行编码त५。我需要将名称保存在mysql数据库中

我问这个问题的原因是我尝试使用UTF-8编码,甚至在表中,我创建了这个

CREATE TABLE `hindi` (
    `data` varchar(200) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
但它给了我
त५当我在文本区域中检索时,它是正确的印地语字符。这没关系。
但当我从数据库检索到pdf文件时,问题就开始了,我只得到了
त५

请告诉我该怎么办? 字符集和编码都是utf-8

更新: 生成pdf的代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page trimDirectiveWhitespaces="true" %>
   <%@ page import="javax.servlet.http.*,javax.servlet.*,com.lowagie.text.Document,com.lowagie.text.DocumentException,com.lowagie.text.Paragraph" %>
   <%@page import="java.io.*,java.text.SimpleDateFormat,com.lowagie.text.pdf.BaseFont,com.lowagie.text.pdf.PdfContentByte,com.lowagie.text.pdf.PdfTemplate"%>
   <%@page import="java.sql.*,java.nio.charset.Charset,com.lowagie.text.pdf.PdfWriter,java.awt.Graphics2D"%>
   <%@ page import="java.util.List,java.util.Arrays,java.util.Collections,java.util.*,com.itextpdf.text.pdf.*,com.itextpdf.tool.xml.ElementList,com.itextpdf.text.Rectangle,com.itextpdf.text.Element,com.itextpdf.text.*,com.itextpdf.text.Font,java.awt.Color,com.itextpdf.text.Font.FontFamily,java.util.Date,java.text.*,com.itextpdf.tool.xml.XMLWorkerHelper" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% 

List arrlist = new ArrayList();
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/a", "root", "root");
Statement st=con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs;
st.executeQuery("SET NAMES UTF8");
rs=st.executeQuery("SELECT * FROM hindi");

while(rs.next()){
arrlist.add(rs.getString("data"));
}  
System.out.println(arrlist);
// step 1: creation of a document-object
Document document = new Document();
        try {
            // step 2:
            // we create a writer
            PdfWriter writer = PdfWriter.getInstance(
            // that listens to the document
                    document,
                    // and directs a PDF-stream to a file
                    new FileOutputStream("C:/Users/hindi.pdf"));
            // step 3: we open the document
            document.open();
            // step 4:
            String text = "&#2361;&#2379;";
            //String arialuniTff = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
            //String x=new String(,Charset.forName("UTF-8"));
            BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf",
                    BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            for(int i=0;i<2;i++){
                  String str =(String) arrlist.get(i);
            document.add(new Paragraph(str,
                    new com.lowagie.text.Font(bf, 12)));
            }
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(100, 50);
            cb.addTemplate(tp, 36, 750);
        } catch (DocumentException de) {
            System.err.println(de.getMessage());
        } catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }

        // step 5: we close the document
        document.close();


%>
</body>
</html>

在此处插入标题

生成PDF时,将charecter set headers设置为utf-8(
charset=utf-8
)。
可能此链接符合您的目的。请根据您的要求进行更改。

在MySQL连接字符串中,您必须添加一些额外的配置,如

jdbc:mysql://localhost/unicode?useUnicode=true&characterEncoding=UTF-8 jdbc:mysql://localhost/unicode?useUnicode=true&characterEncoding=UTF-8 我创建了一个连接类,可以连接到MySQL。请参阅包含类的链接。这是一个swing项目,你可以从那里得到一些帮助

尝试改变表格结构,如下所示

-- -- Database: `unicode` -- CREATE DATABASE `unicode` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `unicode`; -- -------------------------------------------------------- -- -------------------------------------------------------- -- -- Table structure for table `unicode` -- CREATE TABLE IF NOT EXISTS `unicode` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `job` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=20 ; -- --数据库:`unicode` -- 创建数据库“unicode”默认字符集utf8 COLLATE utf8\u general\u ci; 使用“unicode”; -- -------------------------------------------------------- -- -------------------------------------------------------- -- --表` unicode的表结构` -- 如果不存在“unicode”,则创建表( `id`int(11)非空自动增量, `name`varchar(100)不为空, `job`varchar(50)不为空, 主键(`id`) )ENGINE=InnoDB默认字符集=utf8自动增量=20; 当你写作时

String text = "&#2361;";
在Java中,该字符串有7个字符。总是这样。你可能是想写信

String text = String.valueOf((char)2361) + String.valueOf((char)2379);


符号形式仅在HTML和XML中有效,而在Java中无效。

它被设置为charset=utf-8尝试解码utf-8承租人,并使用jsp中的一些解码功能发送到PDF
。什么是页面编码??。我认为没有必要。
contentType=“text/html;charset=UTF-8”
将其更改为
contentType=“application/pdf;charset=UTF-8”
是否有方法将印地语字体编码存储为//u2192编码而不是஬?是的。更改数据库并重试。如果您的网页显示正确,则在创建pdf时可能会出现另一个问题。请确保在更改之前获得备份。我创建了一个新的数据库,但它仍然存储
त्ज
在unicode表中..我正在从jsp页面输入数据库有没有办法将印地语字体编码存储到//u2192编码而不是஬?
String text = "\u0939\u094B";