📄 notesdao.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * NotesDAO.java * * Created on 24 April 2003, 14:38 */package crms.dao;import java.sql.*;import java.io.*;import crms.vo.Note;import java.util.*;import java.text.*;import org.apache.log4j.Logger;/** * * @author dmurphy */public class NotesDAO extends AbstractDAO { static Logger logger = Logger.getLogger(NotesDAO.class); public static SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy h:mm a"); /** Creates a new instance of NotesDAO */ public NotesDAO() { } public List getNotes(String noteType, int noteReference, String user ) { String sql = "SELECT * from \"Notes\"\n"; sql += "WHERE \"NoteType\" = " + quoteSingle(noteType); sql += "\n AND \"NoteReference\" = " + noteReference; sql += "\n AND (\"User\"='"+user+"' OR \"AccessLevel\" < 1 ) "; sql += "\nORDER BY \"NoteDate\" DESC"; ArrayList notes = (ArrayList) executeQuery(sql); return notes; } public void insertNote(Note note) { String sql = "INSERT into \"Notes\"\n"; sql += "(\"NoteType\",\"NoteReference\",\"NoteDate\",\"User\",\"NoteText\",\"AccessLevel\")\n"; sql += "VALUES\n"; sql += "(" + quoteSingle(note.getNoteType()); sql += ", " + note.getNoteReference(); sql += ", " + quoteSingle(df.format(note.getNoteDate())); sql += ", " + quoteSingle(note.getUser()); sql += ", " + quoteSingle(encode(note.getNoteText())); sql += ", " + note.getAccessLevel(); sql += ")"; logger.debug("Executing sql:"); logger.debug(sql); Connection con = null; Statement stmt = null; try { con = this.getFactory().getConnection(); stmt = con.createStatement(); int result = stmt.executeUpdate(sql); if (result != 1 ) { logger.error("Incorrect number of rows updated!"); throw new RuntimeException("Incorrect number of rows updated!"); } } catch (SQLException ex) { logger.fatal(ex); throw new RuntimeException(ex); } finally { try { if (stmt != null) { stmt.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { logger.fatal(ex); throw new RuntimeException(ex); } } } public Object createFromResultSet(ResultSet rs) throws SQLException, UnsupportedEncodingException { Note note = new Note(); note.setNoteID(rs.getInt("NoteID")); note.setNoteType(rs.getString("NoteType")); Timestamp ts = rs.getTimestamp("NoteDate"); note.setNoteDate(new java.util.Date(ts.getTime())); note.setNoteReference(rs.getInt("NoteReference")); note.setNoteText(decode(rs.getString("NoteText"))); note.setUser(rs.getString("User")); note.setAccessLevel(rs.getInt("AccessLevel")); return note; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -