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.SimpleDateFormat("yyyy-MM");
java.util.Date currentTime_1=new java.util.Date();
dateString=formatter.format(currentTime_1);
}catch(Exception e){
}
return dateString;
}
//-------------------------------取得时间
public String strNowtime(){
String dateString="123";
try{
java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
java.util.Date currentTime_1=new java.util.Date();
dateString=formatter.format(currentTime_1);
}catch(Exception e){
}
return dateString;
}
//--------------------------去掉html---------------------------
public String HTMLEncode(String Str){
Str=ebbReplace(Str,"<","<");
Str=ebbReplace(Str,">",">");
Str=ebbReplace(Str," ","<BR>");
return Str;
}
//--------------------------替换变量---------------------------
public String ebbReplace(String Str,String oldStr,String newStr){
String ReturnStr="";
int i,j,t,m,n;
n=0;
j=oldStr.length();
if (Str.indexOf(oldStr)>-1)
{
while(Str.indexOf(oldStr,n)>-1)
{
i=Str.length();
if (Str.indexOf(oldStr)==0)
Str=newStr+Str.substring(j,i);
else
{
t=Str.indexOf(oldStr);
m=(t+j);
Str=Str.substring(0,t)+newStr+Str.substring(m,i);
n=t+newStr.length()-j+1;
}
}
}
ReturnStr=Str;
return ReturnStr;
}
//----------------------------ubb替换--------------------------
public String LCReplace(String Str,String BStr,String EStr,String ReStr){
String ReturnStr="",Str1="",Str2="";
int i,j,n;
n=0;
if ((Str.indexOf(BStr)>-1)&&((Str.indexOf(EStr)>-1)))
{
while(Str.indexOf(BStr,n)>-1)
{
i=Str.indexOf(BStr);
j=Str.indexOf(EStr);
Str1=Str.substring((i+BStr.length()),j);
Str2=ebbReplace(ReStr,"$lichao$",Str1);
Str1=BStr+Str1+EStr;
Str=ebbReplace(Str,Str1,Str2);
n=i+Str2.length()-Str1.length();
}
}
ReturnStr=Str;
return ReturnStr;
}
}
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.SimpleDateFormat("yyyy-MM");
java.util.Date currentTime_1=new java.util.Date();
dateString=formatter.format(currentTime_1);
}catch(Exception e){
}
return dateString;
}
//-------------------------------取得时间
public String strNowtime(){
String dateString="123";
try{
java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
java.util.Date currentTime_1=new java.util.Date();
dateString=formatter.format(currentTime_1);
}catch(Exception e){
}
return dateString;
}
//--------------------------去掉html---------------------------
public String HTMLEncode(String Str){
Str=ebbReplace(Str,"<","<");
Str=ebbReplace(Str,">",">");
Str=ebbReplace(Str," ","<BR>");
return Str;
}
//--------------------------替换变量---------------------------
public String ebbReplace(String Str,String oldStr,String newStr){
String ReturnStr="";
int i,j,t,m,n;
n=0;
j=oldStr.length();
if (Str.indexOf(oldStr)>-1)
{
while(Str.indexOf(oldStr,n)>-1)
{
i=Str.length();
if (Str.indexOf(oldStr)==0)
Str=newStr+Str.substring(j,i);
else
{
t=Str.indexOf(oldStr);
m=(t+j);
Str=Str.substring(0,t)+newStr+Str.substring(m,i);
n=t+newStr.length()-j+1;
}
}
}
ReturnStr=Str;
return ReturnStr;
}
//----------------------------ubb替换--------------------------
public String LCReplace(String Str,String BStr,String EStr,String ReStr){
String ReturnStr="",Str1="",Str2="";
int i,j,n;
n=0;
if ((Str.indexOf(BStr)>-1)&&((Str.indexOf(EStr)>-1)))
{
while(Str.indexOf(BStr,n)>-1)
{
i=Str.indexOf(BStr);
j=Str.indexOf(EStr);
Str1=Str.substring((i+BStr.length()),j);
Str2=ebbReplace(ReStr,"$lichao$",Str1);
Str1=BStr+Str1+EStr;
Str=ebbReplace(Str,Str1,Str2);
n=i+Str2.length()-Str1.length();
}
}
ReturnStr=Str;
return ReturnStr;
}
}