Jsp message board source code 4: for jsp beginners.

Source: Internet
Author: User

Prepared by: precom (pig)
OpDb. java
========================================================== ====
Package ymbean;

Import java. SQL .*;
Import java. util .*;
Import java. text .*;
Import com. chinazjj. SQL. dsql;
Import com. chinazjj. util. dutil;

// I will not post the content in other packages dsql and dutil. The two functions used in this file are very simple.

Single
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.exe cuteQuery (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.exe cuteUpdate (SQL );
System. out. println ("executeUpdate:" + SQL );
Lstmt.exe cuteUpdate ("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>" ========================= ========================
// Remove the strange one:
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;
}

// Convert/n to press ENTER <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;
}

// Convert <br> to press enter/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 + "'");

}

// ============================== Zhangjiajie citizen virtual community management ======================== ==================

======
Public String getDeptSuper (String vp) // obtain the moderator
{
String vst = "unknown ";
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) // obtain the version name
{
String vst = "unknown ";
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) // obtain the community user email
{
String vst = "unknown ";
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) // obtain the community user email and other
{
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) // obtain the community user email and other
{
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.