Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
    public static void main(String args[]) throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        String userName = "suru";
        String password = "password";
        Connection con = DriverManager.getConnection(url, userName, password);
        System.out.println("Connection success!");
        Statement stmt = con.createStatement();
        String sql = "CREATE TABLE EMP ( ID NUMBER(5) PRIMARY KEY, NAME VARCHAR2(50))";
        stmt.execute(sql);
        System.out.println("Table created successfully!");
        stmt.close();
        con.close();
    }
}