Hey,
I use this method to get the news from my mySQL database:
When I run my program, it takes a while to load because of it, and when I call the method again it has to connect to the database again and it freezes the program. I was just wondering where can I get a better method to get the data from MySQL?Code:public void getNews() {
sM("Connecting to DB", Color.BLACK);
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
sM("ERROR ON LINE 158 : " + ex.toString() + "", Color.RED);
}
Connection con = null;
try {
con = (Connection) DriverManager.getConnection("jdbc:mysql://da****t/****w", "d******", "k***");
} catch (SQLException ex) {
sM("ERROR ON LINE 164 : " + ex.toString() + "", Color.RED);
}
PreparedStatement statement = null;
try {
statement = (PreparedStatement) con.prepareStatement("select * from news ORDER BY `id` DESC LIMIT 0 , 1");
sM("Getting the news", Color.BLACK);
} catch (SQLException ex) {
sM("ERROR ON LINE 171 : " + ex.toString() + "", Color.RED);
}
ResultSet result = null;
try {
result = statement.executeQuery();
} catch (SQLException ex) {
sM("ERROR ON LINE 177 : " + ex.toString() + "", Color.RED);
}
try {
while (result.next()) {
newsLabel1.setText(result.getString(2));
}
} catch (SQLException ex) {
sM("ERROR ON LINE 184 : " + ex.toString() + "", Color.RED);
}
sM("Done!", Color.GREEN);
try {
sM("Closing the connection", Color.RED);
con.close();
} catch (SQLException ex) {
sM("ERROR ON LINE 191 : " + ex.toString() + "", Color.RED);
}
sM("Done!", Color.GREEN);
sM("-------------------------------------------------", Color.GREEN);
}

