-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathInsertingData.java
More file actions
31 lines (23 loc) · 864 Bytes
/
InsertingData.java
File metadata and controls
31 lines (23 loc) · 864 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
// Program to insert data into the table
package src.college.understanding_DBConnectivity;
import java.sql.*;
public class InsertingData {
public static void main(String[] args) {
Connection con = null;
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
System.out.println("Connected to DB");
// Query string to insert data into the DataBase.
String query = "INSERT INTO t1 values(1, 'Harshit')";
Statement st = con.createStatement();
st.execute(query);
} catch (Exception e){
System.out.println(e);
}
System.out.println("Exiting....");
}
}