我有MySQL數(shù)據(jù)庫(kù),在那里我保存了數(shù)據(jù),有些單詞有變音符號(hào)。這是我的函數(shù)如何從數(shù)據(jù)庫(kù)獲取數(shù)據(jù)。public List<RowType> getData(String query){ List<RowType> list = new ArrayList<>(); try{ connect(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query); while(resultSet.next()){ StringBuilder str = new StringBuilder(); for(int i = 1; i <= getCountColumns(resultSet); i++){ if(i==1) str.append(resultSet.getString(i)); else str.append("," + resultSet.getString(i)); } list.add(new RowType(str.toString())); } } catch(Exception e){ System.out.println("Chyba p?i získavání údaj? z databáze."); System.out.println(e); Console.print("Chyba p?i získavání údaj? z databáze."); Console.print(e.toString()); } finally{ disconnect(); } return list;}作為參數(shù),我發(fā)送此查詢。List<RowType> list = connection.getData("Select id from countries where name = '?esko'");但它沒(méi)有找到任何東西,因?yàn)槲以诓樵冎杏凶円舴?hào)(“?esko”)。我嘗試沒(méi)有變音符號(hào),它的工作原理。所以你不知道如何修復(fù)它以使用口音嗎?
1 回答

吃雞游戲
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
是否可以嘗試在執(zhí)行主查詢之前再添加幾個(gè)查詢?所以它看起來(lái)像這樣:
connect();
Statement statement = connection.createStatement();
String query2 = "SET NAMES 'utf8'";
statement.execute(query2);
query2 = "SET CHARACTER SET 'utf8'";
statement.execute(query2);
ResultSet resultSet = statement.executeQuery(query);
如果上述方法對(duì)您不起作用,則可能是您的數(shù)據(jù)庫(kù)設(shè)置有問(wèn)題;如果是這種情況,您可以參考此處的答案
添加回答
舉報(bào)
0/150
提交
取消