Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cmpsc221.examples.JDBC;
- import java.sql.*;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- public class DBTest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try{
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://127.0.0.1/glidegame";
- Connection con = DriverManager.getConnection(url, "root", "");
- Statement stmt = con.createStatement();
- int r = stmt.executeUpdate(
- "INSERT INTO `glidegame`.`highscores` ("+
- "`Name` ,"+
- "`Score` ,"+
- "`Time of Score`"+
- ")"+
- "VALUES ("+
- "'UserName', '00:01:31' , TIMESTAMP("+
- "CURRENT_TIMESTAMP )"+
- ");");
- }catch (Exception ex)
- {
- System.out.println("Exception occurred: ");
- ex.printStackTrace();
- }
- try{
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://127.0.0.1/glidegame";
- Connection con = DriverManager.getConnection(url, "root", "");
- Statement stmt = con.createStatement();
- ResultSet r = stmt.executeQuery("select * from highscores");
- String s = new String();
- s = "Name" + "---" + "Score" + "---" + "Time of Score" + '\n';
- while(r.next())
- {
- s+= r.getString("Name") + " --- " + r.getString("Score") + " --- " + r.getString("Time of Score") + '\n';
- }
- System.out.println(s);
- JOptionPane.showMessageDialog(null, s, "High Scores", JOptionPane.INFORMATION_MESSAGE);
- }catch (Exception ex)
- {
- System.out.println("Exception occurred: ");
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement