mysql 데이터베이스에서 주어진 힌디어 단어를 검색하고 데이터베이스에 저장된 영어로 해당 이름을 검색하는 프로그램을 작성했습니다. 힌디어 단어를 직접 입력하면 올바르게 작동합니다. 선택 진술하지만 그것은 더 일반적 일 수 있으므로 변수를 사용하여주고 싶습니다. 그러나 동일한 결과를 얻지 못했습니다. 누군가가 해결책을 도울 수 있습니까? adavance에 대한 고맙습니다.데이터베이스에서 힌디어 문자를 검색합니다
이것은 내가 작성한 코드입니다
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import com.microsoft.sqlserver.jdbc.*;
import java.sql.*;
public class Example {
public static void main(String[] argv) {
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
System.out.println("Where is your MySQL JDBC Driver?");
e.printStackTrace();
return;
}
Connection connection = null;
SQLServerDataSource dataSource = new SQLServerDataSource();
dataSource.setServerName("COMP-PC");
dataSource.setPortNumber(1433);
dataSource.setDatabaseName("concept");
dataSource.setUser("root");
dataSource.setPassword("abc");
try
{
connection = dataSource.getConnection();
connection.setAutoCommit(false);
System.out.println("Connected to server !!!");
Statement select = connection.createStatement();
String var="N'हल्दी'";
ResultSet result = select.executeQuery
("SELECT Name, Id FROM MConcept where CName=N'हल्दी'");
**// When given like the above statement it works fine
("SELECT Name, Id FROM MConcept where CName='"+var+" ' ");
**//This does not give result
System.out.println("Got results:");
while(result.next()) { // process results one row at a time
String Name = result.getString(1);
int ID = result.getInt(2);
System.out.println("name = " + Name);
System.out.println("id = " + ID);
}
select.close();
connection.close();
}
catch (SQLException e)
{
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null)
{
System.out.println("Successfully connected!");
}
else
{
System.out.println("Failed to make connection!");
}
}
}
내가 N과 같이 주어 졌을 때 데이터베이스에 힌디어 값을 저장 할 수 있었다 'हल्दी' 나는 단지 단어 हल्दी를 받았을 때 ???? ???? 내 데이터베이스 Turmeric처럼 보입니다. हल्दी 1 Turmeric은 영어로 된 이름이고, हल्दी는 힌디어와 1입니다. – user1448447
예, 결과가 나타났습니다. 따옴표에 문제가있었습니다. 모든 친구들에게 감사드립니다. 도움 – user1448447