-
Notifications
You must be signed in to change notification settings - Fork 243
/
createdatabase_table.java
31 lines (22 loc) · 1.02 KB
/
createdatabase_table.java
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
import java.sql.*;
public class createdatabase_table {
public static void main (String args[]) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306","root","failers@12345");
Statement stmt=con.createStatement();
int a = stmt.executeUpdate("create database student");
System.out.print(a);
int b = stmt.executeUpdate("use student");
System.out.print(b);
int c = stmt.executeUpdate("create table details (adm_no int,name varchar(30),age int,address varchar(50))");
System.out.print(c);
PreparedStatement stmt1=con.prepareStatement("insert into details values(101,?,20,?)");
stmt1.setString(1,"Akhil");
stmt1.setString(2,"Krishna nivas");
int d =stmt1.executeUpdate();
System.out.print(d);
}
catch(Exception e){System.out.print(e);}
}
}