📄 noteimpl.java
字号:
/* * 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -