Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package studentSystem;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Chingiz Mammadli
- */
- public class Database {
- public Connection conn = null;
- public Database(){
- if(getConnection()){
- System.out.println("Connected");
- }else{
- System.out.println("Not connected");
- }
- }
- private boolean getConnection(){
- String url = "jdbc:mysql://localhost:3306/java_web";
- String username = "root";
- String password = "";
- try{
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(url,username,password);
- return true;
- }catch(Exception e){
- System.out.println(e.getMessage());
- Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, e);
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment