資源簡介
這個是一個日記本程序,主要目的是用來記錄一些技術方面的信息。包括網絡上的,還有其他方面獲得的信息。這個都存儲在數據庫中。本程序由Java編寫。IDE為Netbeans6.7.1 OS為Ubuntu9.10
代碼片段和文件信息
/*
?*?To?change?this?template?choose?Tools?|?Templates
?*?and?open?the?template?in?the?editor.
?*/
package?jemydiary;
import?java.sql.SQLException;
import?java.sql.Statement;
import?java.sql.Connection;
import?java.sql.ResultSet;
import?java.util.Calendar;
import?java.util.Vector;
import?java.util.logging.Level;
import?java.util.logging.Logger;
/**
?*
?*?@author?jinxinxin
?*/
public?class?ContactSystem?{
????public?String[]?initInfoFromSystem(){
????????Connection?con=DBAccessFactory.createDBAccess().getConnection();
????????String?queryStr=“SELECT?category?FROM?category“;
????????Vector?result=new?Vector();
????????try?{
????????????Statement?stat?=?con.createStatement();
????????????ResultSet?rs=stat.executeQuery(queryStr);
????????????while(rs.next()){
????????????????result.add(rs.getString(“category“));
????????????}
????????????String?resultList[]=new?String[result.size()];
????????????result.toArray(resultList);
????????????return?resultList;
????????}?catch?(SQLException?ex)?{
????????????Logger.getLogger(ContactSystem.class.getName()).log(Level.SEVERE?null?ex);
????????}finally{
????????????try?{
????????????????con.close();
????????????}?catch?(SQLException?ex)?{
????????????????Logger.getLogger(ContactSystem.class.getName()).log(Level.SEVERE?null?ex);
????????????}
????????}
????????return?null;
????}
????public?boolean?updateInfoOfSystem(String?titleint?catIDString?content){
????????String?date=null;
????????Calendar?c=Calendar.getInstance();
????????int?year=c.get(Calendar.YEAR);
????????int?month=c.get(Calendar.MONTH);
????????int?day=c.get(Calendar.DAY_OF_MONTH);
????????int?hour=c.get(Calendar.HOUR_OF_DAY);
????????int?minute=c.get(Calendar.MINUTE);
????????int?second=c.get(Calendar.SECOND);
????????date=year+“-“+month+“-“+day+“?“+hour+“:“+minute+“:“+second;
????????Connection?con=DBAccessFactory.createDBAccess().getConnection();
????????String?updateStr=“INSERT?INTO?notes(titlecontentdatecategory_id)?values?(‘“+title+“‘‘“+content+“‘‘“+date+“‘“+catID+“)“;
????????System.out.println(updateStr);
????????try?{
????????????Statement?stat?=?con.createStatement();
????????????stat.executeUpdate(updateStr);
????????????return?true;
????????}?catch?(SQLException?ex)?{
????????????Logger.getLogger(ContactSystem.class.getName()).log(Level.SEVERE?null?ex);
????????}finally{
????????????try?{
????????????????con.close();
????????????}?catch?(SQLException?ex)?{
????????????????Logger.getLogger(ContactSystem.class.getName()).log(Level.SEVERE?null?ex);
????????????}
????????}
????????return?false;
????}
????
}
- 上一篇:java版進程調度模擬器
- 下一篇:基于J2EE技術的物流管理系統的設計與實現
評論
共有 條評論