-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJDBC.java
48 lines (40 loc) · 988 Bytes
/
JDBC.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
package pane;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBC {
public static void main(String[] args) {
Connection c=null;
Statement s=null;
try {
Class.forName("com.mysql.jdbc.Driver");
c=DriverManager
.getConnection
("jdbc:mysql://127.0.0.1:3306/how2java?characterEncoding=UTF-8",
"root","admin");
s=c.createStatement();
for(int i=0;i<100;i++) {
String sql="insert into hero values(null,"+"'hero"+i+"'"+","+313.0f+","+50+")";
s.execute(sql);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
}finally{
if(s!=null)
try {
s.close();
}catch(SQLException e) {
e.printStackTrace();
}
if(c!=null)
try {
c.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
}