package feng;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.awt.Toolkit;
import java.awt.*;
public class jdbc {
Connection conn = null ;
//设置你的数据库用户名和密码:
String use = "" ;
String pass = "" ;
public java.sql.Connection getConn(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Count";
conn= DriverManager.getConnection(url,use,pass);
}
catch(Exception e){
e.printStackTrace();
}
return this.conn ;
}
public String ex_chinese(String str){
if(str==null){
str ="" ;
}
else{
try {
str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
}
catch (Exception ex) {
}
}
return str ;
}
public String gettime() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH") ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
public String getHour() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("H") ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
public String getMonth() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-M") ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
public String getStrMonth() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("M") ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
public String getStrDay() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("d") ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
public String getDay() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-M-d") ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
public String getWeek() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("E") ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
public int getTime1ToTime2(String Time1) {
String StrDate=Time1;
int i=StrDate.indexOf("-");
String ip1=StrDate.substring(0,i);
StrDate=StrDate.substring(i+1,StrDate.length());
i=StrDate.indexOf("-");
String ip2=StrDate.substring(0,i);
StrDate=StrDate.substring(i+1,StrDate.length());
i=StrDate.indexOf(" ");
String ip3=StrDate.substring(0,i);
StrDate=StrDate.substring(i+1,StrDate.length());
java.util.Date StartDate=new java.util.Date(Integer.valueOf(ip1).intValue()-1900,Integer.valueOf(ip2).intValue(),Integer.valueOf(ip3).intValue());
long aa=StartDate.getTime();
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH") ;
StrDate = df.format(new java.util.Date()) ;
i=StrDate.indexOf("-");
ip1=StrDate.substring(0,i);
StrDate=StrDate.substring(i+1,StrDate.length());
i=StrDate.indexOf("-");
ip2=StrDate.substring(0,i);
StrDate=StrDate.substring(i+1,StrDate.length());
i=StrDate.indexOf(" ");
ip3=StrDate.substring(0,i);
StrDate=StrDate.substring(i+1,StrDate.length());
java.util.Date StartDate1=new java.util.Date(Integer.valueOf(ip1).intValue()-1900,Integer.valueOf(ip2).intValue(),Integer.valueOf(ip3).intValue());
long bb=StartDate1.getTime();
return (int)(bb-aa)/(24*60*60*1000);
}
public void AddNum(String Data,String TbName,String CompareField,String AddField,String admin){
try{
Connection con2 = getConn() ;
Statement stmt3=con2.createStatement();
Statement stmt4=con2.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs2 =null;
String sql="Select * From "+TbName+" Where "+CompareField+"='"+Data+"' and admin='"+admin+"'";
rs2=stmt4.executeQuery(sql) ;
rs2.last();
if (rs2.getRow()>0){
sql="update "+TbName+" set "+AddField+"="+AddField+"+1 "+" Where "+CompareField+"='"+Data+"' and admin='"+admin+"'";
stmt3.executeUpdate(sql) ;
} else {
sql="insert into "+TbName+"(admin,"+CompareField+","+AddField+") values('"+admin+"','"+Data+"',1)" ;
stmt3.executeUpdate(sql);
}
rs2.close();
stmt3.close();
stmt4.close();
con2.close();
}
catch (Exception ex) {
}
}
public void ModiMaxNum(String CurData,String OldData,String OldNum,String MaxData,String MaxNum,String admin){
try{
Connection con = getConn() ;
Statement stmt1=con.createStatement();
Statement stmt2=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet Rs =null;
String sql="Select * From InfoList where admin='"+admin+"'";
Rs=stmt2.executeQuery(sql);
Rs.next();
String FStrDate=Rs.getString(OldData);
int count=Rs.getInt(OldNum);
if (FStrDate.equals(CurData)){
count=count+1;
} else {
FStrDate=CurData;
count=1;
}
int FmaxNum=Rs.getInt(MaxNum);
String FMaxData=Rs.getString(MaxData);
if (count>=FmaxNum){
FmaxNum=count;
FMaxData=CurData;
}
sql="update InfoList set "+OldData+"='"+FStrDate+"',"+OldNum+"="+count+","+MaxData+"='"+FMaxData+
"',"+MaxNum+"="+FmaxNum+" Where admin='"+admin+"'";
stmt1.executeUpdate(sql);
Rs.close();
stmt1.close();
stmt2.close();
con.close();
}
catch (Exception ex) {
}
}
}
- 1
- 2
- 3
- 4
前往页