⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 examquestiondao.java

📁 本系统是用NetBeans IDE 6.1所写
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.online.dao;import com.online.pojo.Item;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import javax.naming.Context;import javax.naming.InitialContext;import javax.sql.DataSource;public class ExamQuestionDAO {        private static final String GET_EXAM_ITEMS = "SELECT * FROM EItem ";        private DataSource datasource;        public ExamQuestionDAO() {                try {            Context ctx = new InitialContext();            datasource = (DataSource) ctx.lookup("jdbc/OnlineExamDB");        } catch (Exception e) {            e.printStackTrace();        }    }        public List getExamQuestion() {                List examQuestion = new ArrayList();        Connection con = null;        PreparedStatement ps = null;        ResultSet rs = null;                try {            con = datasource.getConnection();            ps = con.prepareStatement(GET_EXAM_ITEMS);            rs = ps.executeQuery();            while(rs.next()) {                Item item = new Item(                        rs.getString("QID"),                        rs.getString("QUESTION"),                        rs.getString("OPTION_A"),                        rs.getString("OPTION_B"),                        rs.getString("OPTION_C"),                        rs.getString("OPTION_D"),                        rs.getString("S_ANSWER")                        );                examQuestion.add(item);            }        } catch (SQLException se) {            se.printStackTrace();        } finally {            if(rs != null) {                try { rs.close(); } catch (Exception e) { e.printStackTrace(); }            }            if(ps != null) {                try { ps.close(); } catch (Exception e) { e.printStackTrace(); }            }            if(con != null) {                try { con.close(); } catch (Exception e) { e.printStackTrace(); }            }        }        return examQuestion;    }}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -