Use Bean and Servlet in Jsp to implement user registration
Source: Internet
Author: User
Article title: using Bean and Servlet in Jsp to implement user registration. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The software and operating environment required in this example:
1. Windows Server operating system
2. jdk1.4
3. JCreator2.5 (java source code editor debugger)
4. Macromedia JRun MX
5. Macromedia Dreamweaver MX (not required)
6. MySQL database (preferably MySQL Control Center)
I. database design Use MySQL Control Center to open the MySQL database, create a database shopping, and create a table tbl_user under it. The fields are set as follows:
// Perform the query operation
Public ResultSet executeQuery (String strSql)
{
Try {
This. rs = stmt.exe cuteQuery (strSql );
Return this. rs;
} Catch (SQLException e ){
System. out. println (e. toString ());
Return null;
} Catch (NullPointerException e ){
System. out. println (e. toString ());
Return null;
}
}
// Insert, delete, and modify data
Public boolean execute (String strSql)
{
Try {
If(this.stmt.exe cuteUpdate (strSql) = 0)
Return false;
Else
Return true;
} Catch (SQLException e ){
System. out. println (e. toString ());
Return false;
} Catch (NullPointerException e ){
System. out. println (e. toString ());
Return false;
}
}
// Jump the result set pointer to a row
Public boolean rs_absolute (int row)
{
Try {
This. rs. absolute (row );
Return true;
} Catch (SQLException e ){
System. out. println (e. toString ());
Return false;
}
}
Public void rs_afterLast ()
{
Try {
This. rs. afterLast ();
} Catch (SQLException e ){
System. out. println (e. toString ());
}
}
Public void rs_beforeFirst ()
{
Try {
This. rs. beforeFirst ();
} Catch (SQLException e ){
System. out. print (e. toString ());
}
}
Public void rs_close ()
{
Try {
This. rs. close ();
} Catch (SQLException e ){
System. out. print (e. toString ());
}
}
Public void rs_deleteRow ()
{
Try {
This. rs. deleteRow ();
} Catch (SQLException e ){
System. out. print (e. toString ());
}
}
Public boolean rs_first ()
{
Try {
This. rs. first ();
Return true;
} Catch (SQLException e ){
System. out. print (e. toString ());
Return false;
}
}
Public String rs_getString (String column)
{
Try {
Return this. rs. getString (column );
} Catch (SQLException e ){
System. out. println (e. toString ());
Return null;
}
}
// This method is used to obtain large text segments,
// Replace the carriage return line
// Output to the html page
Public String rs_getHtmlString (String column)
{
Try {
String str1 = this. rs. getString (column );
String str2 = "\ r \ n ";
String str3 ="
";
Return this. replaceAll (str1, str2, str3 );
} Catch (SQLException e ){
System. out. println (e. toString ());
Return null;
}
}
// Replace str2 string in str1 with str3 string
Private static String replaceAll (String str1, String str2, String str3)
{
StringBuffer strBuf = new StringBuffer (str1 );
Int index = 0;
While (str1.indexOf (str2, index )! =-1)
{
Index = str1.indexOf (str2, index );
StrBuf. replace (str1.indexOf (str2, index), str1.indexOf (str2, index) + str2.length (), str3 );
Index = index + str3.length ();
Public int rs_getInt (String column)
{
Try {
Return this. rs. getInt (column );
} Catch (SQLException e ){
System. out. println (e. toString ());
Return-1;
}
}
Public int rs_getInt (int column)
{
Try {
Return this. rs. getInt (column );
} Catch (SQLException e ){
System. out. println (e. toString ());
Return-1;
}
}
Public boolean rs_next ()
{
Try {
Return this. rs. next ();
} Catch (SQLException e ){
System. out. println (e. toString ());
Return false;
}
}
// Determine whether there is data in the result set
Public boolean hasData ()
{
Try {
Boolean has_Data = this. rs. first ();
This. rs. beforeFirst ();
Return has_Data;
} Catch (SQLException e ){
System. out. println (e. toString ());
Return false;
}
}
Public boolean rs_last ()
{
Try {
Return this. rs. last ();
} Catch (SQLException e ){
System. out. println (e. toString ());
Return false;
}
}
Public boolean rs_previous ()
{
Try {
Return this. rs. previous ();
} Catch (Exception e ){
System. out. println (e. toString ());
Return false;
}
}
// Main method for debugging
Public static void main (String args [])
{
Try {
DBConn myconn = new DBConn ();
// Myconn. setDBName ("shopping ");
// Myconn. DBConn ();
// Myconn.exe cute ("Insert Into tbl_test (id, name) values ('10', 'shandaer ')");
// Myconn.exe cute ("Update tbl_test set name = 'yyyyyyyyyy' where id = 10 ");
// Myconn.exe cute ("Delete from tbl_test where id = 1 ");
ResultSet rs = myconn.exe cuteQuery ("select * from tbl_user order by id desc limit 1 ");
// Boolean hasData = myconn. hasData ();
// System. out. println ("has data:" + hasData );
// Rs. first ();
While (myconn. rs. next ())
{
Int id = myconn. rs_getInt ("id") + 1;
System. out. print (id );
System. out. println (myconn. rs_getInt ("id") + myconn. rs_getString ("name "));
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