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 |
String driver = "com.mysql.jdbc.Driver" ; String u = "root" ; String p = "sa123456" ; try
{ Class.forName(driver); Connection con = DriverManager.getConnection(url,u,p); if (!con.isClosed()){ System.out.println( "链接成功..." ); Statement statement = con.createStatement(); String sql = "select * from articles" ; String insertSql = "insert into articles(title,content) values(?,?)" ; //执行查询操作 ResultSet rs = statement.executeQuery(sql); PreparedStatement ps = con.prepareStatement(insertSql); ps.setString( 1 , "哈哈哈1111" ); ps.setString( 2 , "写入数据成功啦...." ); //执行增、删、改操作 ps.executeUpdate(); while (rs.next()){ System.out.println(rs.getString( "content" )); } rs.close(); con.close(); } } catch
(ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } |
原文:http://www.cnblogs.com/huangzelin/p/3525608.html