jdbc写入和读取过程
[jdbc寫操作]
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/big","root","root");
ppst = conn.preparedStatement("insert into test(id,name,age) values(?,?,?)");
//綁定參數(shù)
ppst.setInteger(1,1);
ppst.setString(2,"tom");
ppst.setInteger(3,"tom");
ppst.executeUpdate();
ppst.close();
ppst.close();
?
[jdbc讀操作]
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/big4","root","root");
ppst =conn.PreparedStatement("select id,name from test");
ResultSet rs = ppst.executeQuery();
while(rs.next()){
int id = rs.getInt();
String name = rs.getString("name");
}
rs.close();
conn.close();
轉(zhuǎn)載于:https://www.cnblogs.com/stone-learning/p/9271732.html
總結(jié)
以上是生活随笔為你收集整理的jdbc写入和读取过程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自定义控件优化
- 下一篇: linux系统数据落盘之细节