jsp留言板原始碼四: 給jsp初學者._JSP編程

來源:互聯網
上載者:User
作 者: 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
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.