欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp留言板源代码四: 给jsp初学者.

程序员文章站 2024-02-26 11:40:22
作 者: precom (皮蛋) 其中的opdb.java ============================================ package ymb...
作 者: precom (皮蛋)
其中的opdb.java
============================================
package ymbean;

import java.sql.*;
import java.util.*;
import java.text.*;
import com.chinazjj.sql.dsql;
import com.chinazjj.util.dutil;

//其他的包dsql,dutil中的内容我就不再贴了,在本文件中用到的两个函数都很简


public class opdb {

private string inquire_value="",inquire_item="",disptype="",inqtyp

e="";
private string inquire_num="",inquire_addr="",inquire_name="";
private dutil ldutil=new dutil();
public opdb() {

}

public void setinquire_item(string name) { inquire_item= name

;}
public void setinquire_value( string name ) { inquire_value = ldut

il.chinesetounicode(name);}
public void setdisptype(string name) { disptype=name;}
public void setinqtype(string name) { inqtype=name;}

public void setinquire_num( string name ) { inquire_num = ldutil.c

hinesetounicode(name);}
public void setinquire_addr( string name ) { inquire_addr = ldutil

.chinesetounicode(name);}
public void setinquire_name( string name ) { inquire_name = ldutil

.chinesetounicode(name);}

public string getinquire_dndata()
{
return "";
}

public resultset executequery(string sql)
{
resultset rs = null;
statement lstmt = null;
try {
lstmt = connectdb();
rs = lstmt.executequery(sql);
system.out.println("executequery: "+sql);
} catch(sqlexception ex) { system.err.println("executequery: " +

ex.getmessage());}
return rs;
}

public statement getstmt()
{
statement lstmt = null;
lstmt = connectdb();
return lstmt;
}

public string executeupdate(string sql)
{
resultset rs = null;
statement lstmt = null;
try {
lstmt = connectdb();
lstmt.executeupdate(sql);
system.out.println("executeupdate: "+sql);
lstmt.executeupdate("commit");
}
catch(sqlexception ex) { system.err.println("executequery: " + e

x.getmessage());
return(ex.getmessage());
}
return("executeupdate ok");
}

public statement connectdb()
{

statement lstmt=null;
connection conn=null;

final string connect_string="jdbc:oracle:thin:scott/tiger@192.168.

0.1:1521:clubdb";
final string driver_string="oracle.jdbc.driver.oracledriver";
dsql mysql=new dsql();
lstmt=mysql.dconnectdb(driver_string,connect_string);
return lstmt;
}

public statement connectdb(string connect_string)
{
statement lstmt=null;
connection conn=null;

final string driver_string="oracle.jdbc.driver.oracledriver";
dsql mysql=new dsql();
lstmt=mysql.dconnectdb(driver_string,connect_string);
return lstmt;
}


//=========other function ===================================

public string getcurrentdate(string ldateform)
{
return(new simpledateformat(ldateform).format(new java.util.date(

)));
}

//========"/n" to "<br>" =====================================
//去掉奇怪的:
public string removecomment(string content){
string makecontent=new string();
stringtokenizer strtoken=new stringtokenizer(content,"\n");
string temptoken=null;

while(strtoken.hasmoretokens()){
temptoken=strtoken.nexttoken();
if(temptoken.indexof(":")!=0)
makecontent=makecontent+temptoken+"\n";
}
return makecontent;
}

//将/n转换成为回车<br>
public string addbr(string content){
string makecontent=new string();
stringtokenizer strtoken=new stringtokenizer(content,"\n");
while(strtoken.hasmoretokens()){
makecontent=makecontent+"<br>"+strtoken.nexttoken();
}
return makecontent;
}

//将<br>转换成为回车/n
public string addcr(string content){
string makecontent=new string();
stringtokenizer strtoken=new stringtokenizer(content,"<br>");
while(strtoken.hasmoretokens()){
makecontent=makecontent+"\n"+strtoken.nexttoken();
}
return makecontent;
}


//====================================================================

=====
public boolean getidentify(string name1,string pwd1)
{
try
{
string sql="select * from club_users where username='" + name1 + "'

and password='" + pwd1 + "'";
resultset rs = executequery(sql);
if(rs.next()) { rs.close(); return(true);}
else { rs.close();return(false);}
}catch (exception e) { return(false);}
}

public void counts(string pagename)
{
executeupdate("update call_count set counts=counts + 1 where pagenam

e='"+pagename+"'");

}

//==================张家界市民虚拟社区管理============================

======
public string getdeptsuper(string vp) //取版主
{
string vst="未知";
try{
string sql="select administrator from club_cvcdept where deptno=

'"+vp+"'";
resultset rs = executequery(sql);
if(rs.next()) vst=rs.getstring(1);
rs.close();
} catch (exception e) {}
return vst;
}
public string getdeptname(string vp) //取版名
{
string vst="未知";
try{
string sql="select deptnote from club_cvcdept where deptno='"+vp

+"'";
resultset rs = executequery(sql);
if(rs.next()) vst=rs.getstring(1);
rs.close();
} catch (exception e) {}
return vst;
}

public string getuseremail(string vp) //取社区用户email
{
string vst="未知";
try{
string sql="select email from club_users where username='"+vp+"'

";
resultset rs = executequery(sql);
if(rs.next()) vst=rs.getstring(1);
rs.close();
} catch (exception e) {}
return vst;
}

public object getavalue(string vp) //取社区用户email及其他
{
object vst=null;
try{
string sql=vp;
resultset rs = executequery(sql);
if(rs.next()) vst=rs.getobject(1);
rs.close();
} catch (exception e) {}
return vst;
}

public string getsvalue(string vp) //取社区用户email及其他
{
string vst="";
try{
string sql=vp;
resultset rs = executequery(sql);
if(rs.next()) vst=rs.getstring(1);
rs.close();
} catch (exception e) {}
return vst;
}


}//end opdb.java