How make Dtabase Connection(Java)


  • Make a new project (I name it as 'Blog') and I didn't make a main class
  • Make a new java class and I name it as dbCon
  • Now you have to add libery named 'derbyclient.jar'
  • You can download it by this link
  • dearbyclient.jar
  • Now import following libraries
  • import java.sql.*;
    import javax.swing.*;
    
  • Now add following codes in to your method
  • Connection conn=null;
        public static Connection Connect(){
            
            try{
               String host="jdbc:derby://localhost:3306/blog";
               String uName="root";
               String uPass="root";
               Connection conn=DriverManager.getConnection(host, uName, uPass);
    
             
                return connection;
            }
            catch(Exception e){
                JOptionPane.showMessageDialog(null, e.getMessage());
                return null;
    

Next time we will see how enter data to a Database

1 comment:

  1. Interesting! This is really a very useful content for those who are looking for java training in yamunanagar Thank You so much for sharing this with us.

    ReplyDelete