一个实用的javabean
时间:2008-05-07
import java.sql.*;import java.util.*;import java.text.*;import java.io.*;public class jdbc_sql{String conn_str="jdbc:mysql://localhost/HeaVeN_news";//---------数据库String username="root";//---------------数据库用户名String password="";//-------------数据库密码private Connection conn=null;private Statement stmt=null;ResultSet rs=null;//----------------------数据库链接----------------public jdbc_sql(){try{Class.forName("org.gjt.mm.mysql.Driver");}catch(java.lang.ClassNotFoundException e){System.err.println("dbclass():"+e.getMessage());}try{conn=DriverManager.getConnection(conn_str,username,password);}catch(SQLException ex) {System.err.println("dbclass():"+ex.getMessage());}}//---------------------数据库查询-----------------public ResultSet query(String sql){try{stmt=conn.createStatement();rs=stmt.executeQuery(sql);}catch(SQLException ex) {System.err.println("query():"+ex.getMessage());}return rs;}//-----------数据库修改---------public void update(String sql){try{stmt=conn.createStatement();stmt.executeUpdate(sql);}catch(SQLException ex) {System.err.println("update():"+ex.getMessage());}}//----------关闭数据源-------public void closestmt(){try{stmt.close();}catch(SQLException ex) {System.err.println("closestmt():"+ex.getMessage());}}//----------关闭链接---------public void closeconn(){try{conn.close();}catch(SQLException ex) {System.err.println("closeconn()"+ex.getMessage());}}//---------------------转换中文public String toChinese(String s){if(s==null)return null;try{String convert=new String(s.getBytes("gb2312"),"ISO8859-1");return convert;}catch(Exception e){}return null;}//--------------------分页public String page1(int num,int line,int page_line,int start,int page,String search,String filename){int pagetotal=line*page_line;//所要显示的总条数int pagestart;//int pagenum;//int total=(num-start+line-1)/line;//取得总页数int total_start=(num+pagetotal-1)/pagetotal;//取得总偏移数String returnstr="";if(start!=0){int old_start=start-pagetotal;returnstr+=" <a href="+filename+"?page=0&start="+old_start+search+"><<</a>";}pagestart=start/pagetotal*page_line;//取得当前页数for(int i=0;i<total&&i<page_line;i++){pagenum=pagestart+i+1;returnstr+=" <a href="+filename+"?page="+i+"&start="+start+search+">"+pagenum+"</a>";}if(total_start!=(start/pagetotal+1)&&num!=0){int new_start=start+pagetotal;returnstr+=" <a href="+filename+"?page=0&start="+new_start+search+">>></a>";}return returnstr;}//-------------------------------取得时间public String GetPath(){String dateString="123";try{java.text.SimpleDateFormat formatter=new java.text.Simpl
|