如何优化 JAVA 应用程序(用 Netbeans 编写)和我的 MYSQL 数据库(托管在外部数据库提供商)之间的速度?
假设我有以下代码;
private void fillPlayersList()
{
try
{
PlayerListModel.clear();
Connection userConn = SimpleDataSource.getConnection();
Statement userStat = userConn.createStatement();
String userquery = "SELECT * FROM player";
ResultSet userResult = userStat.executeQuery(userquery);
if(userResult.next())
{
PlayerList.setEnabled(true);
userResult.previous();
while (userResult.next()) {
int id = userResult.getInt("player_id");
String username = userResult.getString("username");
String ip = userResult.getString("ip");
PlayerListModel.addElement(new PlayerItem(id, username, ip));
}
}
userConn.close();
PlayerList.setModel(PlayerListModel);
}
catch(SQLException e)
{
System.out.println(e);
}
}
这需要aaaggeeesss才能完成!如何优化这样的代码?
谢谢!