-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.java
98 lines (69 loc) · 2.75 KB
/
setup.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.company;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;
public class setup {
String Database;
String tablename;
int column_no;
/* String [] columnname;
String [] datatype;
String [] size;*/
String columnname = "sagar";
String datatype = "varchar";
String size = "12";
Scanner sc = new Scanner(System.in);
/* public void createdatabase() {
System.out.println("please provide Database name to be created");
Database = sc.next();
try {
// conection establish
String url = "jdbc:mysql:///";
String username ="root";
String password ="Sagar@321";
Connection connect = DriverManager.getConnection(url,username,password);
Statement state = connect.createStatement(); // create statement
System.out.println("connection succesffull !");
String Query = "create database "+Database; //execute query
state.execute(Query);
System.out.println("Database created Successfully !");
connect.close(); //connection close
}catch (Exception e){
System.out.println(e);
}
} */
public void createtable(){
System.out.println("Enter table name");
tablename = sc.next();
/* System.out.println("Enter no of columns to be created");
column_no= sc.nextInt();
for (int i=0; i<column_no; i++){
System.out.println("Enter names of columns");
columnname[i]=sc.next();
System.out.println("Enter dataypes of columns");
datatype[i]=sc.next();
System.out.println("Enter size of columns");
size[i]=sc.next();
} */
try {
// conection establish
String url = "jdbc:mysql:///demo";
/// String db = "demo";
String username ="root";
String password ="Sagar@321";
Connection connect = DriverManager.getConnection(url,username,password);
Statement state = connect.createStatement(); // create statement
//
String sql = "CREATE TABLE tablename"+
"(id INTEGER not NULL, " +
" first VARCHAR(255), " +
" age INTEGER)";
state.executeUpdate(sql);
System.out.println(tablename+"created succesffull !");
connect.close(); //connection close
}catch (Exception e){
System.out.println(e);
}
}
}