Facebook Twitter Instagram
    DeepCrazyWorld
    Facebook Twitter Instagram Pinterest YouTube
    • FLUTTER
      • FLUTTER APP
        • QRCode
        • Quiz App
        • Chat GPT
        • PDF App
        • News App
        • Fitness App
        • Weather App
        • BMI Calculator
        • GAME APP
        • Ecommerce App
        • wallpaper App
        • Finance app
        • Chat App
        • Wallet App
        • Taxi App
        • Quran app
        • Music player app
      • FLUTTER UI
        • Splash Screen
        • Onboarding Screen
        • Login Screen
        • Card Design
        • Drawer
    • PROJECT
      • Android Projects
      • College Projects
      • FLUTTER APP
      • Project Ideas
      • PHP Projects
      • Python Projects
    • SOURCE CODE
    • ANDROID
      • ANDROID APP
      • GAME APP
      • ANDROID STUDIO
    • MCQ
      • AKTU MCQ
        • RPA MCQ
        • COA MCQ
        • HPC MCQ
        • SPM MCQ
        • Renewable Energy All MCQ
        • Data Compression MCQ
        • Data Structure MCQ
        • Digital Image Processing MCQ
        • Software Engineering MCQ
        • Machine Learning MCQ
        • Artificial Intelligence MCQ
      • D PHARMA MCQ
        • Pharmaceutics – I MCQ
        • Pharmacognosy MCQ
        • Pharmaceutical Chemistry MCQ
        • Biochemistry and Clinical Pathology MCQ
        • Human Anatomy and Physiology MCQ
        • Heath Education and Community Pharmacy MCQ
    • INTERVIEW QUESTIONS
      • Flutter Interview Questions
      • INTERVIEW QUESTIONS
      • Python Interview Questions
      • Coding ninjas solution
    • MORE
      • WORDPRESS
        • SEO
        • TOP 10 WORDPRESS THEME
      • PRODUCTIVITY
      • Program
      • QUOTES
    DeepCrazyWorld
    Home»Program»How to Connect to MySQL database in Java programming
    Program

    How to Connect to MySQL database in Java programming

    DeepikaBy DeepikaAugust 24, 2019Updated:January 19, 2022No Comments1 Min Read

    How to Connect to MySQL database in Java programming
    In this instructional exercise, you will figure out how to associate with MySQL database utilizing JDBC Connection object. To interface with MySQL database from a Java program, you need …

    Program to create connection with database in java programming language.

    /*
     create database deep;  
    use deep;  
    create table emp(id int(10),name varchar(40),age int(3));  
    */
    
    
     import java.sql.*;  
    class MysqlConn
    {  
    public static void main(String args[])
    {  
    try
    {  
    Class.forName("com.mysql.jdbc.Driver");
      
    Connection con=DriverManager.getConnection(  
    "jdbc:mysql://localhost:3306/deep","root","root"); 
     
    //here deep is database name, root is username and password
      
    Statement stmt=con.createStatement();  
    
    ResultSet rs=stmt.executeQuery("select * from emp"); 
     
    while(rs.next())  
    System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3)); 
     
    con.close();  
    
    }
    catch(Exception e)
    {
     System.out.println(e);}  
    }  
    }    

    Share. Facebook Twitter LinkedIn WhatsApp Telegram Pinterest Reddit Email
    Previous ArticlePrint HELLO WORLD in Java without using semicolon ‘;’
    Next Article Download Photo Editor App Android Studio with source code

    Related Posts

    Top 5 Best Programming Languages To Learn in 2023

    Program 7 Mins Read

    OOP’s Concept Code – Basic operations and Relational Operators

    ANDROID STUDIO 3 Mins Read

    How to make a Piano using C++ Programming Language | source code Free

    Program 2 Mins Read

    Java Advance Top 50+ Interview Questions!

    INTERVIEW QUESTIONS 15 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile March 29, 2025
    • Creating an Instruction UI Screen in Flutter Application March 29, 2025
    • Animated Backgrounds in Flutter: A Complete Guide March 15, 2025
    • How to make Diary App using flutter stepwise using getx August 31, 2024
    • How to Create Music Player UI screen with fully functional in flutter August 30, 2024
    • How to make ListView Builder Ui in flutter with Source Code August 29, 2024
    • Create a TabBar View in flutter with fully functional stepwise August 28, 2024
    • How to create TabBar view in flutter with source code step wise August 27, 2024
    • How to make Heart rate measure app with Flutter stepwise August 26, 2024
    • How to make ChatGpt App in flutter with source code Stepwise August 25, 2024
    Facebook Twitter Instagram Pinterest YouTube
    • About
    • Contact
    • Disclaimer
    • Privacy Policy
    Copyright by DeepCrazyWorld © 2025

    Type above and press Enter to search. Press Esc to cancel.