-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbConnection.java
More file actions
41 lines (35 loc) · 1.18 KB
/
DbConnection.java
File metadata and controls
41 lines (35 loc) · 1.18 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
package com.pak;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class DbConnection {
public static Connection getconnection(){
Connection con=null;
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test","root","root");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return con;
}
public static void main(String[] args) {
Connection conn = DbConnection.getconnection();
try {
//Statement st = conn.createStatement();
Statement st1 = conn.createStatement();
// ResultSet rs = st.executeQuery("Select * from Student");
int rs1 = st1.executeUpdate("Insert into Student(`firstname`,`lastname`) Values ('abg1','abuaf')");
System.out.println("insertion done");
/*while(rs1.next()){
System.out.println("Id:"+rs1.getString("id")+",fName:"+rs1.getString("firstname")+",lName:"+rs1.getString("lastname"));
}*/
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Done");
}
}