Practical-11 Develop a database application that uses any JDBC driver

 

import java.sql.*;

public class DbDemo

{

    public static void main(String[] args)

    {

        Connection conn;

        Statement stmt;

        try

        {

            Class.forName("com.mysql.cj.jdbc.Driver");

            System.out.println("Trying to connect with Database Server..");

            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/","root", "");

            System.out.println("Connection Established Successfully...");

            System.out.println("Trying to create Database..");

            stmt = con.createStatement();

            String sql = "CREATE DATABASE STUDENTDB";

            stmt.executeUpdate(sql);

            System.out.println("Database Created Successfully...");

            sql = "USE STUDENTDB";

            stmt.executeUpdate(sql);

            System.out.println("Trying to create Table..");            

            sql = "CREATE TABLE STUDINFO(rollno int, name varchar(50),mobile int)";            

            stmt.executeUpdate(sql);

            System.out.println("Table Created Successfully...");

            con.close();

            stmt.close();

        }

        catch(SQLException e)

        {

            System.out.println("Exception Caught." + e);

        }

    }

}

Output:

Trying to connect with Database Server..

Connection Established Successfully...

Trying to create Database..

Database Created Successfully.

Trying to create Table..

Table Created Successfully...

Comments

Popular posts from this blog

Write a program to check whether empty query string is entered in Asp.Net.

Mandavrayji Temple, Muli, Surendranagar, Gujarat

Write a program to change color of Label text control programmatically in Asp.Net.