jdbc

简单使用:
1首先获得数据库连接
Connection conn = MyJdbcConnection.getConn();
2然后从conn对象中获得statement
PreparedStatement ps=conn.prepareStatement(sql);
3然后从ps中获得结果集
ResultSet rs=ps.executeQuery();
 
操作结束需要关闭连接
 
1.1获得连接
首先加载驱动类
Class.forName(dbInfo.getDriver());
然后获得连接
DriverManager.getConnection(dbInfo.getUrl(),dbInfo.getUser(),dbInfo.getPassword());
 
 
con.setAutoCommit(false);//设置手动提交
 
ps = conn.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,//设置结果集可滚动,可跳行
ResultSet.CONCUR_READ_ONLY);//设置其他用户的操作是只读
 
String idStr="zy' or '1'='1";
 
String sql="select id,balance from account" +
" where id='"+idStr+"'";//安全隐患,sql注入
rs=s.executeQuery(sql);

posted @ 2014-08-16 18:53  乱笙歌  阅读(73)  评论(0)    收藏  举报