1.新建一個項目
2添加mysql驅(qū)動
3新建一個類
2添加mysql驅(qū)動
3新建一個類
1
2
import java.sql.*;
3
4
5
public class test {
6
7
/**
8
* @param args
9
*/
10
public static void main(String[] args) {
11
// TODO Auto-generated method stub
12
try {
13
new com.mysql.jdbc.Driver();
14
//Class.forName(com.mysql.jdbc.Driver)
15
} catch (Exception e) {
16
// TODO Auto-generated catch block
17
e.printStackTrace();
18
}
19
Connection conn=null;
20
Statement stmt=null;
21
ResultSet rs=null;
22
23
String sql="xxx";
24
25
try {
26
conn=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/oltest","root","4873617");
27
stmt=conn.createStatement();
28
rs=stmt.executeQuery(sql);
29
30
} catch (SQLException e) {
31
// TODO Auto-generated catch block
32
e.printStackTrace();
33
}
34
35
36
}
37
38
}
39

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
