-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJDBCCreateDBDemo.java
More file actions
35 lines (26 loc) · 936 Bytes
/
JDBCCreateDBDemo.java
File metadata and controls
35 lines (26 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.sjcet.db;
import java.sql.*;
public class JDBCCreateDBDemo {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/";
//Database username & password
static final String USER = "admin";
static final String PWD = "sjcet123";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Connection con = null;
Statement statement = null;
//1. Register JDBC Driver
Class.forName(JDBC_DRIVER);
//2. Open a connection
System.out.println("Connecting to DB....");
con = DriverManager.getConnection(DB_URL,USER,PWD);
//3. Create Statement
statement = con.createStatement();
//4.Execute a Query
String sql = "create database student";
boolean result = statement.execute(sql);
if(result) {
System.out.println("Data base created successfully...");
}
}
}