Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Statement statement;
- public DatabaseConnection(){
- try{
- String driver = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://localhost:3306/mygame";
- String username = "root";
- String password = "root";
- //Class.forName(driver);
- Connection con = DriverManager.getConnection(url,username,password);
- statement = con.createStatement();
- System.out.println("Connected to database!");
- } catch(Exception e){
- System.out.println(e);
- System.out.println("Connection fail");
- }
- }
- public void getAllGames() {
- try {
- ResultSet rs = statement.executeQuery("select * from game ORDER by game_name");
- while(rs.next()){
- System.out.println(rs.getString(2));
- }
- }catch (SQLException ex){
- System.out.println("executing fail");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement