设为首页 加入收藏

TOP

MySQL的简单操作方法:Statement、PreparedStatement(二)
2015-07-24 11:31:33 来源: 作者: 【 】 浏览:5
Tags:MySQL 简单 操作 方法 Statement PreparedStatement
tion e) { e.printStackTrace(); } DBUtil.close(connection, null, preparedStatement, null); return commentList; }

(4)使用Statement操作数据库

public List
getArticleMessage() { Connection connection = DBUtil.getConn(); String sql = "select * from article";// 编写sql语句,第一个字段不需要插入,是自动增加的 Statement statement = null; List
articleList = new ArrayList
(); try { statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sql); //判断是否为空 if (rs.next()) { while (rs.next()) {//将信息迭代到list中 Article article = new Article(); article.setTitle(rs.getString("title")); article.setContext(rs.getString("context")); article.setArticleTime(rs.getString("articletime")); article.setUserid(rs.getInt("userid")); article.setArticleid(rs.getInt("articleid")); articleList.add(article); } } else { return null; } } catch (SQLException e) { e.printStackTrace(); } DBUtil.close(connection, statement, null, null); return articleList; }
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇如何设置mysql的表不区分你大小写 下一篇MySQL联结表

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)