noteimpl.java

来自「jsp+servlet网上购物,是一个实现mvc的网站」· Java 代码 · 共 54 行

JAVA
54
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.ebook.impl;import java.util.*;import java.sql.*;import com.ebook.dao.*;import com.ebook.Entity.*;import java.text.SimpleDateFormat;public class NoteImpl implements NoteDao {    Connection con;    public NoteImpl(Connection con) {        this.con = con;    }    public ArrayList getNote() throws Exception {        PreparedStatement pstm;        ArrayList list = new ArrayList();        String sql = "select * from note";        pstm = con.prepareStatement(sql);        ResultSet rs = pstm.executeQuery();        while (rs.next()) {            Note note = new Note();            note.setUserid(rs.getInt("Noteid"));            note.setUsername(rs.getString("Username"));            note.setContent(rs.getString("Notecontent"));            note.setTime(rs.getString("Notetime"));            list.add(note);        }        return list;    }     public void addNote(Note note) throws Exception {        PreparedStatement pstm;        String sql = "insert into note(Userid,Username,Notecontent,Notetime) values(?,?,?,?)";        pstm = con.prepareStatement(sql);        pstm.setInt(1,note.getUserid());        pstm.setString(2, note.getUsername());        pstm.setString(3,note.getContent());        pstm.setString(4,getDate());        pstm.executeUpdate();     }        public String getDate() {        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");        String time = df.format(new java.util.Date());        return time;    }   }

⌨️ 快捷键说明

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