Reputation: 1
I have a MySQL database that i am trying to load into a java application i am making. It is to show the current online players in a minecraft server. I have it setup to where the Server updates the database when a person leaves or joins. I need it to load into a control panel that shows online players, and allows the to stop/start/restart the server.
Thanks
Upvotes: 0
Views: 8807
Reputation: 41
If you are using the Swing Framework and only want to connect to a database you need the driver and the jdbc to manage the connections. Here you can download the driver.
And for using it, I'll link you the MySQL's manual here.
Another thing: Once, I needed to make a kind of time line like twitter's and surfing in the web I fount one or two articles where they explained how to make SQL Server produce a sort of signal to make you know a new register is in the data base and then you can update your data in real time, but as that was a DBA job and we had no DBA, I had to use a thread which automatically updated every 60000 milliseconds.
Upvotes: 2
Reputation: 14816
What have you done till now, any SSCCE?
Here is the code that shows how to retrive data's from mySQL database:
public void selectFromSomeTable(){
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String dbUrl = "jdbc:mysql://nameOfTheHost/yourDBname";
String dbUsr = "dbUsername";
String dbPass = "dbPassword";
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection (dbUrl,dbUsr,dbPass);
st = conn.createStatement();
rs = st.executeQuery("SELECT * FROM someTable");
while(rs.next()){
//Get values
String someValue =rs.getString("name_of_the_column");
.
.
.
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
This is all I can do for you now.
Upvotes: 2