avasqlConnection;
4 import javasqlDriverManager;
5 import javasqlPreparedStatement;
6 import javasqlResultSet;
7 import javasqlSQLException;
8
9
10 public class TestCon1{
11 public static void main(String[] args)
12 {
13 Connection 買粉絲n = null;
14 String sql;
15 PreparedStatement pre;
16 ResultSet rs;
17
18 try {
19 String driver="mysqljdbcDriver";
20 ClassforName(driver);
21
22 String url="jdbc:mysql:localhost:3306/cuiuseUni買粉絲de=trueutf-8也行
23 買粉絲n = DriverManagergetConnection(url, "root", "123456");
24
25 sql = "select _id,username,password from test1" ;
26 pre = 買粉絲nprepareStatement(sql);
27
28 rs = preexecuteQuery();
29 while(rsnext()){
30 int id = rsgetInt(1);
31 String username = rsgetString(2);
32 String password = rsgetString(3);
33
34 Systemoutprintln("id="+id+";username="+username+";password="+password);
35 }
36 買粉絲nclose();
37 } catch (SQLException e) {
38 eprintStackTrace();
39 } catch (ClassNotFoundException e) {
40 eprintStackTrace();
41 }
42
43 }
44
45 }
運行結果:
id=1;username=c;password=123456
id=2;username=xxx;password=654321
id=3;username=ddd;password=123456
id=4;username=ddf÷;password=yyt
id=5;username=cuixiaodong;password=cxd
id=6;username=vv;password=cxd
手機軟件開發難學嗎手機軟件開發,技術含量很高。 只有接受好的教育,有好的學習態度才會不難
2024-07-07 06:28
2024-07-07 05:56
2024-07-07 05:45
2024-07-07 05:40
2024-07-07 05:14
2024-07-07 04:51