我正在尝试制作一个简单的Mysql SELECT查询
这是我的代码:
public Highscore[] load_localscores() {
// load preferences
SharedPreferences hiscores = PreferenceManager.getDefaultSharedPreferences(screen.getApplicationContext());
Highscore highscore[] = new Highscore[highscore_number];
for (int i = 0; i < highscore_number; i++) {
highscore[i] = new Highscore();
highscore[i].highscore = HERE_SELECTED_MYSQL_DATA;
highscore[i].hiscorename = HERE_SELECTED_MYSQL_DATA;
}
return highscore;
在Mysql数据库中,我有两个字段Hightscore.name和Hightscore.score
我想从我的表中选择数据到HERE_SELECTED_MYSQL_DATA
我道歉,我对JAVA并不熟悉。答案 0 :(得分:0)
答案 1 :(得分:0)
try{
String selectSQL = "select * from Hightscore";
Statement stmt = conn.createStatement();
ResultSet rs1 = stmt.executeQuery(selectSQL);
System.out.println(rs1.getString("name"));
System.out.println(rs1.getString("score"));
}
catch(SQLException se) {
System.err.println(se);
}
希望这会有所帮助,它会获得结果集,但您必须事先建立连接。如果你想得到关于这方面的建议,我也可以给出这个建议吗?