锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美亚洲一级,综合激情一区,久久久天天操http://www.aygfsteel.com/flynewton/archive/2009/04/03/263816.htmlflynewtonflynewtonFri, 03 Apr 2009 12:32:00 GMThttp://www.aygfsteel.com/flynewton/archive/2009/04/03/263816.htmlhttp://www.aygfsteel.com/flynewton/comments/263816.htmlhttp://www.aygfsteel.com/flynewton/archive/2009/04/03/263816.html#Feedback0http://www.aygfsteel.com/flynewton/comments/commentRss/263816.htmlhttp://www.aygfsteel.com/flynewton/services/trackbacks/263816.html 1 import java.io.IOException;
 2 import java.io.InputStream;
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.ResultSet;
 6 import java.sql.Statement;
 7 import java.util.Properties;
 8 
 9 public class JdbcMySql {
10 
11     public static Properties getProperties() {
12         Properties props = new Properties();
13         InputStream is = null;
14         try {
15             is = JdbcMySql.class.getResourceAsStream("/jdbc_mysql.properties");
16             props.load(is);
17         } catch (Exception e) {
18             e.printStackTrace();
19             return null;
20         } finally {
21             if(is != null
22                 try {
23                     is.close();
24                 } catch (IOException e) {
25                     e.printStackTrace();
26                 }
27         }
28         return props;
29     }
30     
31     public static void main(String[] args) {
32         Connection conn = null;
33         Statement stmt = null;
34         ResultSet rs = null;
35         
36         Properties props = getProperties();
37         if (props != null) {
38             String driver = props.getProperty("driver");
39             String url = props.getProperty("url");
40             String user = props.getProperty("user");
41             String password = props.getProperty("password"); 
42             String characterEncoding = props.getProperty("characterEncoding");
43             
44             try {
45                 Class.forName(driver);
46                 conn = DriverManager.getConnection(url + "?characterEncoding=" + characterEncoding, user, password);
47                 stmt = conn.createStatement();
48                 
49                 String sql = "delete from student where id = '2'";
50                 stmt.executeUpdate(sql);
51                 
52                 sql = "select * from student";
53                 rs = stmt.executeQuery(sql);
54                 
55                 while (rs.next()) {
56                     System.out.print(rs.getInt(1+ "\t");
57                     System.out.print(rs.getString(2+ "\t");
58                     System.out.print(rs.getString(3+ "\n");
59                 }
60             } catch (Exception e) {
61                 e.printStackTrace();
62             } finally {
63                 try {
64                     if (rs != null
65                         rs.close();
66                     if (stmt != null
67                         stmt.close();
68                     if (conn != null)
69                         conn.close();
70                 } catch (Exception ex) {
71                     ex.printStackTrace();
72                 }
73             }
74         }
75     }
76 }

flynewton 2009-04-03 20:32 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 广灵县| 三台县| 启东市| 于田县| 阿瓦提县| 西城区| 萍乡市| 东乡| 都安| 长岭县| 内乡县| 娄底市| 麻江县| 板桥市| 木里| 隆林| 昌宁县| 宣汉县| 平度市| 玉山县| 兴安盟| 元朗区| 安宁市| 南乐县| 托克逊县| 盐亭县| 宣城市| 墨玉县| 紫金县| 廊坊市| 石阡县| 吉水县| 萨迦县| 休宁县| 泽普县| 海城市| 仪陇县| 昌江| 阿合奇县| 芜湖县| 郧西县|