我试图插入和检索泰米尔语(语言)值。但我变得像 #wrapperWithScrollbarForOutput {
background-color: #453750;
width: 200px;
height: 200px;
position: relative;
overflow-y: auto;
}
#outputDivForText {
background-color: #73648A;
display: table-cell;
vertical-align: bottom;
width: 50px;
height: 200px;
overflow: auto;
}
#inputDiv {
background-color: #9882AC;
}
。
插入查询,
??????
我的代码,
"INSERT INTO category VALUES (19, 'இந்தியா நாட்டின்','A');"
注意:
我的配置,
public static void main(String[] args) {
System.out.println("");
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = (Connection) DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
try{
Statement st = (Statement) conn.createStatement();
st.executeQuery("select categoryname from category");
ResultSet rs = st.getResultSet();
int count = 0 ;
while(rs.next()){
String name = rs.getString("categoryname");
System.out.println("Vlalue "+ name);
++count;
}
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
您必须在连接中使用Connection connection = DriverManager.getConnection(
"jdbc:mysql://db_name?useUnicode=true&characterEncoding=utf-8", "root", "pass");
:
CREATE TABLE table_name
(
...
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
我认为您的数据库是这样创建的:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ConnectionJSon {
static String driver = "com.mysql.jdbc.Driver";
static String DB_username = "root";
static String DB_password = "admin";
static String DB_URL =
"jdbc:mysql://localhost:3306/d3?useUnicode=true&characterEncoding=utf-8";
public static void main(String[] args) throws Exception {
try {
Connection connection = DriverManager.getConnection(DB_URL,
DB_username, DB_password);
String q = "INSERT INTO table1 VALUES (?)";
PreparedStatement preparedStatement = connection.prepareStatement(q);
preparedStatement.setString(1, "இந்தியா நாட்டின்");
int exc = preparedStatement.executeUpdate();
System.out.println(exc);
q = "SELECT * FROM table1";
preparedStatement = connection.prepareStatement(q);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(1));
}
System.out.println("Success");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
以下是我的结果的示例:
修改强>
<强>代码强>
create table table1(
col varchar(30)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
<强> SQL 强>
this->setProperty("qsysKernelType", QSysInfo::kernelType());
this->setProperty("qsysCurrentCpuArchitecture", QSysInfo::currentCpuArchitecture());
this->setProperty("qsysBuildCpuArchitecture", QSysInfo::buildCpuArchitecture());
this->setProperty("qsysProductType", QSysInfo::productType());
答案 1 :(得分:0)
您的表/数据库使用的字符集/排序规则不支持泰米尔语字符。最有可能的是,您希望整个数据库都支持Tamil。这样,无论何时创建新表,它都将支持泰米尔语。
CREATE DATABASE yourDatabase
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
如果这不起作用,那么您的MySQL版本可能不支持utf8mb4
字符集。在这种情况下,请尝试仅使用utf8
。
答案 2 :(得分:0)
您应该在mysqli函数之后添加的简单内容
mysqli_set_charset( $db, 'utf8');
替换$ db代替您的db连接变量。