-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
26 lines (24 loc) · 1.01 KB
/
App.java
File metadata and controls
26 lines (24 loc) · 1.01 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
import java.sql.DriverManager;
import java.sql.*;
public class App {
private static final String JDBC_URL = "jdbc:mysql://localhost:3306/db";
private static final String DB_USER = "root";
private static final String DB_PASSWORD = "";
public static void main(String[] args) {
try(Connection conn = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PASSWORD)){
Statement st = conn.createStatement();
String cq = "insert into students(id,name,age,department) values (1,'John',20,'cse')";
st.executeUpdate(cq);
System.out.println("Record created succesfully");
String rq = "Select * from Students";
ResultSet rs = st.executeQuery(rq);
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
System.out.println("ID"+id+"Name"+name);
}
}catch(SQLException e){
e.printStackTrace();
}
}
}