-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathcreatetable.java
More file actions
64 lines (34 loc) · 1.3 KB
/
createtable.java
File metadata and controls
64 lines (34 loc) · 1.3 KB
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
package com;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class createtable {
public static void main(String[] args) throws ClassNotFoundException, SQLException{
// createTable();
// insert();
}
public static Connection getConnection() throws ClassNotFoundException, SQLException
{
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:dtclass.db");
return connection;
}
public static void createTable() throws ClassNotFoundException, SQLException {
Connection connection = getConnection();
System.out.println(connection);
String query = "Create table admin (username varchar(100), password varchar(100))";
Statement statement = connection.createStatement();
boolean result = statement.execute(query);
System.out.println(result);
connection.close();
}
public static void insert() throws ClassNotFoundException, SQLException {
Connection connection= getConnection();
String sql = "insert into admin values('admin','admin')";
PreparedStatement ps = connection.prepareStatement(sql);
int i = ps.executeUpdate();
System.out.println(i + " row inserted....");
}
}