Date handling cases
Abstract: Date handling cases
</ Td> </ tr> <tr> <td width="562" height="35" valign="top" class="ArticleTeitle"> <% @ page contentType = "text / html; GBK charset ="% >
<% @ Page import = "java.text .*"%>
<% @ Page import = "java.util .*"%>
<%
/ / String into time type (string can be any type, as long as the format and SimpleDateFormat consistent required)
SimpleDateFormat sdf = new java.text.SimpleDateFormat ( "M / dd / yyyy hh: mm: ss" java.util.Locale.US);
Java.util.Date d = sdf.parse ( "5/13/2003 10:31:37 AM");
Out.println (d);
Out.println ( "
");
SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd HH: mm: ss");
String mDateTime1 = formatter.format (d);
Out.println (mDateTime1);
Out.println ( "
");
Out.println (d.getTime ());
Out.println ( "
");
/ / Current time
Calendar cal = Calendar.getInstance ();
/ / SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd HH: mm: ss");
/ / SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd HH: mm: ss GEDF w W a EF");
String mDateTime = formatter.format (cal.getTime ());
Out.println (mDateTime);
Out.println ( "
");
/ / 1 years ago Date
Java.util.Date myDate = new java.util.Date ();
Long myTime = (myDate.getTime () / 1000) -60 * 60 * 24 * 365;
MyDate.setTime (myTime * 1000);
String mDate = formatter.format (myDate);
Out.println (mDate);
Out.println ( "
");
/ / Date tomorrow
MyDate = new java.util.Date ();
MyTime = (myDate.getTime () / 1000) +60 * 60 * 24;
MyDate.setTime (myTime * 1000);
MDate = formatter.format (myDate);
Out.println (mDate);
Out.println ( "
");
/ / 2 the number of days between the time
SimpleDateFormat myFormatter = new SimpleDateFormat ( "yyyy-MM-dd");
Java.util.Date date = myFormatter.parse ( "2003-05-1");
Java.util.Date mydate = myFormatter.parse ( "1899-12-30");
Long day = (date.getTime ()-mydate.getTime ())/( 24 * 60 * 60 * 1000);
Out.println (day);
Out.println ( "
");
/ / And a half hours
SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd hh: mm: ss");
Java.util.Date date1 = format.parse ( "2002-02-28 23:16:00");
Long Time = (date1.getTime () / 1000) +60 * 30;
Date1.setTime (Time * 1000);
String mydate1 = formatter.format (date1);
Out.println (mydate1);
Out.println ( "
");
/ / Week for years Date
SimpleDateFormat formatter2 = new SimpleDateFormat ( "yyyy-MM FE");
Java.util.Date date2 = formatter2.parse (the "2003-6 2 Wednesday");
SimpleDateFormat formatter3 = new SimpleDateFormat ( "yyyy-MM-dd");
String mydate2 = formatter3.format (date2);
Out.println (mydate2);
Out.println ( "
");
/ / For a few weeks
Mydate = myFormatter.parse ( "2001-1-1");
SimpleDateFormat formatter4 = new SimpleDateFormat ( "E");
String mydate3 = formatter4.format (mydate);
Out.println (mydate3);
Out.println ( "
");
%>
</ Td> <td width="169" valign="top" class="ArticleTeitle">
</ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle">
↑ Back
Send e-mail with attachments
Abstract: Send e-mail with attachments
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> continue to Sina as an example, the use of the annex to upload components, the company O'Reilly The cos.jar. Please cos.jar, mail.jar and activation.jar, put it in your application's WEB WEB-INF/lib directory.
Test the JavaMail3.html
<head>
</ Head>
<body>
JavaMail use to send e-mail - Annex
<form Name="SendMessage" Method="post" action="JavaMail3.jsp" enctype="multipart/form-data">
Sender: <input type = "text" name = "From" size = "30" maxlength = "30">
Addressee: <input type = "text" name = "To" size = "30" maxlength = "30">
Subject: <input type = "text" name = "Subject" size = "30" maxlength = "30">
Format: <select name = "Type" size = "1">
<option Value="text/plain"> Text </ option>
<option Value="text/html"> HTML </ option>
</ Select>
Annex: <input type = "file" name = "FileName" size = "20" maxlength = "20">
:
<textarea Name="Message" cols=40 rows=5> </ textarea>
<table Width="669" border="0"> <tr> <td width="391"> <input type="submit" value="å‘é€">
<input Type="reset" value="é‡å¡«">
</ Form>
</ Body>
Annex mail address and JavaMail3.jsp
<% @ Page import = "javax.mail .*"%>
<% @ Page import = "javax.mail.internet .*"%>
<% @ Page import = "javax.activation .*"%>
<% @ Page import = "java.util .*, java.io. *"%>
<% @ Page import = "com.oreilly.servlet.MultipartRequest"%>
<% @ Page contentType = "text / html; charset = GB2312"%>
<head>
</ Head>
<body>
</ Td> <td width="268"> </ td> </ tr> </ table>
JavaMail use to send e-mail - Annex
<%
InternetAddress address [] = null;
Request.setCharacterEncoding ( "gb2312");
MultipartRequest multi = new MultipartRequest (request, ".", 5 * 1024 * 1024, "GB2312");
String mailserver = "smtp.sina.com.cn";
String From = multi.getParameter ( "From");
String to = multi.getParameter ( "To");
String Subject = multi.getParameter ( "Subject");
String type = multi.getParameter ( "Type");
String messageText = multi.getParameter ( "Message");
String FileName = multi.getFilesystemName ( "FileName");
Boolean sessionDebug = false;
Try (
/ / Set by the server and use the Mail Transfer Protocol used by the
Java.util.Properties props = System.getProperties ();
Props.put ( "mail.host" mailserver);
Props.put ( "mail.transport.protocol", "smtp");
Props.put ( "mail.smtp.auth", "true ");// specified the need for SMTP Authentication
/ / Create new services Session
Javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance (props, null);
MailSession.setDebug (sessionDebug);
Message msg = new MimeMessage (mailSession);
/ / Set sender
Msg.setFrom (new InternetAddress (From));
/ / Set the addressee
Address = InternetAddress.parse (to, false);
Msg.setRecipients (Message.RecipientType.TO, address);
/ / Set the theme of the letter
Msg.setSubject (Subject);
/ / Set the time messenger
Msg.setSentDate (new Date ());
If (FileName! = Null)
(
File file = new File (FileName);
/ / If there is annex, first e-mail to some depositors
MimeBodyPart mbp1 = new MimeBodyPart ();
/ / Set for the type of message content, text / plain or text / html
Mbp1.setContent (messageText, type + "; charset = GB2312");
/ / Come on the annex to deal with
MimeBodyPart mbp2 = new MimeBodyPart ();
FileDataSource fds = new FileDataSource (FileName);
Mbp2.setDataHandler (new DataHandler (fds));
Mbp2.setFileName (MimeUtility.encodeText (fds.getName (), "GB2312", "B"));
/ / Then finally integrate the two, as a message sent
Multipart mp = new MimeMultipart ();
Mp.addBodyPart (mbp1);
Mp.addBodyPart (mbp2);
Msg.setContent (mp);
)
Else
(
/ / If no attachment, the e-mail directly deposit
Msg.setContent (messageText, type + "; charset = GB2312");
)
Transport transport = mailSession.getTransport ( "smtp");
/ / E-mail please enter your user name and password, not to use my ^ _ ^.
Transport.connect (mailserver, "zz3zcwb", "1234567");
Transport.sendMessage (msg, msg.getAllRecipients ());
Transport.close ();
Out.println ( "e-mail has been successfully sent");
)
Catch (MessagingException mex)
(
Out.println (mex);
Mex.printStackTrace ();
)
%>
</ Body>
The Annex to me! Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr>
↑ Back
JSP technology page
Abstract: JSP technology page
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="722" border="0"> <tr> <td> </ td> </ tr> </ table>
The current widespread use of the paging option is to cache query results in the HttpSession or state bean, the time from turning the pages out of a cache data. Such an approach has two major drawbacks: First, users may see is measured data; Second, if the volume of data is very large for the first time spent traversing the results of assembly for a long time, and cache data will take up much of memory, efficiency has declined markedly.
Other common methods are also on each page-a database, only removed from a ResultSet data (using rs.last (); rs.getRow (), and was recorded of the total number, use rs.absolute () positioning Go to Start records). In some ways this database (such as oracle) JDBC is the need to achieve almost all records traversing experimental proof in the record number of large, very slow speed.
As for the cache result sets ResultSet methods are is a completely wrong approach. ResultSet because Connection closed or in the Statement will also be closed, if prolonged occupation will ResultSet effective database connection.
Pagination therefore relatively good practice should be the time to turn the pages, each from a database search page size of the data block. Although each page-this need to query the database, but for a very small number of records, not data transmission network, the use of connection pool can be the most time-consuming little more than the establishment of a database linking process. In the database and a variety of mature-optimization techniques used to enhance the speed of enquiries than in the application server cache done more effectively.
In oracle database query results, the Bank said that the use of pseudo-out ROWNUM (from the beginning). For example, select * from employee where rownum <10 return to the previous record of 10. But since rownum in enquiries after the sort of assignment before, so for employee birthday by the sort 100-120 record should write:
[Pre] select * from (
Select my_table .*, rownum as my_rownum from (
Select name, birthday from employee order by birthday
) My_table where rownum <120
) Where my_rownum> = 100
[/ Pre]
MySQL can use the LIMIT clause:
Select name, birthday from employee order by birthday LIMIT 99,20
DB2 has rownumber () function to access the current line number.
SQL Server not studied, can refer to the article: http://www.csdn.net/develop/article/18/18627.shtm
In the process of Web page will be frequently used, but the realization of the details page programming is trouble in the course of things. Most of the paging display query operation at the same time to deal with complex multiple search criteria, sql statement needs dynamic mosaic composition, coupled with the need for paging record positioning, the total number of records, as well as the result of a query on Ergodic, Packaging, and that process will become very complex and difficult to understand. Some of the tools needed to streamline category paging code, programmers focus on the business logic part. Below are the two I design tools categories:
PagedStatement Packaging, a database connection, the record number of enquiries, paging enquiries, outcome data package and the closure of operations such as database connectivity, support and the use of dynamic setting parameters PreparedStatement.
PetStore RowSetPage reference to the page by page iterator pattern for Packaging Design RowSetPage query results (using OracleCachedRowSet from a cache for data on the use of database query results CachedRowSet Packaging, please refer to JSP pages enquiries revealed that commonly used models) as well as the current paginated, and the total number of records, the current record number, and other information, and can generate simple HTML page code.
PagedStatement the results of inquiries into RowsetPage package.
Below is the use of simple examples:
/ / DAO data for some of the code:
…
Public RowSetPage getEmployee (String gender, int pageNo) throws Exception (
String sql = "select emp_id, emp_code, user_name, real_name from employee where gender =?";
/ / Oracle Database tab for realization per page 5
PagedStatement pst = new PagedStatementOracleImpl (sql, pageNo, 5);
Pst.setString (1, gender);
Return pst.executeQuery ();
)
/ / Servlet handle enquiries request of the code:
…
Int pageNo;
Try (
/ / Pageno parameters can be obtained through the user's selection of a page
PageNo = Integer.parseInt (request.getParameter ( "pageno"));
) Catch (Exception ex) (
/ / The default is the first page
PageNo = 1;
)
String gender = request.getParameter ( "gender");
Request.setAttribute ( "empPage" myBean.getEmployee (gender, pageNo));
…
/ / JSP showed some code
<% @ Page import = "page.RowSetPage"%>
…
<script Language="javascript">
Function doQuery () (
Form1.actionType.value = "doQuery";
Form1.submit ();
)
</ Script>
…
<form Name=form1 method=get>
<input Type=hidden name=actionType>
Sex:
<Input type = text name = gender size = 1 value ="<%= request.getParameter ( "gender ")%>">
<input Type=button value="查询" onclick="doQuery()">
<%
RowSetPage empPage = (RowSetPage) request.getAttribute ( "empPage");
If (empPage == null) = RowSetPage.EMPTY_PAGE empPage;
%>
…
<table Cellspacing="0" width="90%">
<tr> <td> ID </ td> <td> code </ td> <td> user name </ td> <td> name </ td> </ tr>
<%
Javax.sql.RowSet empRS = (javax.sql.RowSet) empPage.getRowSet ();
If (empRS! = Null) while (empRS.next ()) (
%>
<tr>
<td> <% = EmpRS.getString ( "EMP_ID ")%></ td>
<td> <% = EmpRS.getString ( "EMP_CODE ")%></ td>
<td> <% = EmpRS.getString ( "USER_NAME ")%></ td>
<td> <% = EmpRS.getString ( "REAL_NAME ")%></ td>
</ Tr>
<%
) / / End while
%>
<tr>
<%
/ / Show the total number of pages and the current page (pageno), as well as paging code.
/ / Here doQuery pages submitted for action on the javascript function name, logo pageno for the parameters of the current page
%>
<td Colspan=4> <% = empPage. GetHTML ( "doQuery", "pageno ")%></ td>
</ Tr>
</ Table>
</ Form>
Figure effect:
Pagination will show that because of the general conditions and with enquiries for action, the page should have a check on the conditions and methods for the javascript (as in the above doQuery), the RowSetPage.getHTML () generated paging code on the user choice new page directly in front of the callback to deal with enquiries javascript methods. Attention to the outcome of the enquiries revealed that the last time on the need to maintain conditions, such as <input type = text name = gender size = 1 value ="<%= request.getParameter ( "gender ")%>">. At the same time as the parameters of a page can be designated, and therefore support in the same pages in a number of paging zones.
Another paging code is generated for each page URL, page inquiry parameters and attached to the URL as QueryString behind. This method is the deficiencies in the conditions for dealing with complex, difficult, and the need for action designated to deal with the servlet, and may not be suitable for certain custom query operation.
If the RowSetPage.getHTML () generation is not satisfied with the default code page can be dealt with the preparation of their own paging code RowSetPage provide many getter methods are used to get the relevant information (such as the current page, total pages, the total number of records and the current record number, etc.).
In practical application can be made and shown on page jsp taglib to further streamline the JSP code, shielding Java Code.
Attachment: Paging Tool of the source code, the Notes should be very easy to understand.
1.Page.java
2.RowSetPage.java (RowSetPage succession Page)
3.PagedStatement.java
4.PagedStatementOracleImpl.java (PagedStatementOracleImpl succession PagedStatement)
You can use any source code, but the word must be preserved author evan_zhao@hotmail.com
///////////////////////////////////
/ /
/ / Page.java
/ / Author: evan_zhao@hotmail.com
/ /
///////////////////////////////////
Package page;
Import java.util.List;
Import java.util.ArrayList;
Import java.util.Collection;
Import java.util.Collections;
/ **
* Title: paging object
* Description: Information contained data and paging targets
* Page class implements used to display basic information page, but not specified the type of data contained,
* According to the need to achieve a particular way of organizing the data-type,
* RowSetPage to RowSet package data, the data package ListPage to List
* Copyright: Copyright (c) 2002
* @ Author evan_zhao@hotmail.com
* @ Version 1.0
* /
Public class Page implements java.io.Serializable (
Public static final Page EMPTY_PAGE = new Page ();
Public static final int DEFAULT_PAGE_SIZE = 20;
Public static final int MAX_PAGE_SIZE = 9999;
Private int myPageSize = DEFAULT_PAGE_SIZE;
Private int start;
Private int avaCount, totalSize;
Private Object data;
Private int currentPageno;
Private int totalPageCount;
/ **
* The default constructor, the only empty page structure
* /
Protected Page () (
This.init (0,0,0, DEFAULT_PAGE_SIZE, new Object ());
)
/ **
* Initial data paging, call by the subclass
* @ Param start page data in the database in the initial position
* @ Param avaCount page contains data of the number of
* @ Param totalSize database records of the total number of
* @ Param pageSize page capacity
* @ Param data page contains data
* /
Protected void init (int start, int avaCount, int totalSize, int pageSize, Object data) (
This.avaCount = avaCount;
This.myPageSize = pageSize;
This.start = start;
This.totalSize = totalSize;
This.data = data;
/ / System.out.println ( "avaCount:" + avaCount);
/ / System.out.println ( "totalSize:" + totalSize);
If (avaCount> totalSize) (
/ / Throw new RuntimeException ( "record of the total number of more than a few ?!");
)
This.currentPageno = (start -1) / pageSize +1;
This.totalPageCount = (totalSize pageSize + -1) / pageSize;
If (totalSize == 0 & & avaCount == 0) (
This.currentPageno = 1;
This.totalPageCount = 1;
)
/ / System.out.println ( "Start Index to Page No:" + start + "-" + currentPageno);
)
Public Object getData () (
Return this.data;
)
/ **
* Data from this page capacity (this page will contain the record number)
* @ Return the records page can include several
* /
Public int getPageSize () (
Return this.myPageSize;
)
/ **
* Whether there is a Next
* @ Return whether there is a Next
* /
Public boolean hasNextPage () (
/ *
If (avaCount == 0 & & totalSize == 0) (
Return false;
)
Return (+ start avaCount -1) <totalSize;
* /
Return (this.getCurrentPageNo () <this.getTotalPageCount ());
}
/ **
* Whether there is a previous
* @ Return whether there is a previous
* /
Public boolean hasPreviousPage () (
/ *
Return start> 1;
* /
Return (this.getCurrentPageNo ()> 1);
)
/ **
* Access to the first page of the data in the database location
* @ Return
* /
Public int getStart () (
Return start;
)
/ **
* Get the current page final data in the database in a position
* @ Return
* /
Public int getEnd () (
Int end = this.getStart () + this.getSize () -1;
If (end <0) (
End = 0;
)
Return end;
)
/ **
* Previous first access data in the database of the location of
* @ Return records corresponding rownum
* /
Public int getStartOfPreviousPage () (
Return Math.max (start-myPageSize, 1);
)
/ **
* Get Next first data in the database of the location of
* @ Return records corresponding rownum
* /
Public int getStartOfNextPage () (
+ AvaCount return start;
)
/ **
* Access to the first page of the data in the database location, number each page of the use of default values
* @ Param pageNo page,
* @ Return records corresponding rownum
* /
Public static int getStartOfAnyPage (int pageNo) (
Return getStartOfAnyPage (pageNo, DEFAULT_PAGE_SIZE);
)
/ **
* Access to the first page of the data in the database location
* @ Param pageNo page,
* @ Param pageSize few records per page
* @ Return records corresponding rownum
* /
Public static int getStartOfAnyPage (int pageNo, int pageSize) (
Int startIndex = (pageNo-1) * pageSize + 1;
If (startIndex <1) startIndex = 1;
/ / System.out.println ( "Page No to Start Index:" pageNo + + "-" + startIndex);
Return startIndex;
)
/ **
* Page from the records contain few
* @ Return page contains a record number of
* /
Public int getSize () (
Return avaCount;
)
/ **
* From the database contains records of the total number of
* @ Return the database contains records of the total number of
* /
Public int getTotalSize () (
Return this.totalSize;
)
/ **
* From the current page
* @ Return the current page
* /
Public int getCurrentPageNo () (
Return this.currentPageno;
)
/ **
* From the page
* @ Return the page
* /
Public int getTotalPageCount () (
Return this.totalPageCount;
)
/ **
*
* @ Param queryJSFunctionName achieve paging JS script name, page will automatically change the method of correction
* @ Param pageNoParamName page parameter name
* @ Return
* /
Public String getHTML (String queryJSFunctionName, String pageNoParamName) (
If (getTotalPageCount () <1) (
Return "<input type='hidden' name='"+pageNoParamName+"' value='1'>";
)
If (queryJSFunctionName == null | | queryJSFunctionName.trim (). Length () <1) (
QueryJSFunctionName = "gotoPage";
)
If (pageNoParamName == null | | pageNoParamName.trim (). Length () <1) (
PageNoParamName = "pageno";
)
String gotoPage = "_" + queryJSFunctionName;
StringBuffer html = new StringBuffer ( "\ n");
Html.append ( "<script language=\"Javascript1.2\"> \ n")
. Append ( "function"). Append (gotoPage). Append ( "(pageNo) (\ n")
. Append ( "var curPage = 1 \ n")
. Append ( "try (curPage = document.all [\" ")
. Append (pageNoParamName). Append ( "\"]. Value; \ n ")
. Append ( "document.all [\" "). Append (pageNoParamName)
. Append ( "\"]. Value = pageNo; \ n ")
. Append ( ""). Append (queryJSFunctionName). Append ( "(pageNo) \ n")
. Append ( "return true; \ n")
. Append ( ") catch (e) (\ n")
/ / Append ( "try (\ n")
/ / Append ( "document.forms [0]. Submit () \ n")
/ / Append ( ") catch (e) (\ n")
. Append ( "alert ( 'not yet defined query methods: function")
. Append (queryJSFunctionName). Append ("()'); \ n ")
. Append ( "document.all [\" "). Append (pageNoParamName)
. Append ( "\"]. Value = curPage; \ n ")
. Append ( "return false; \ n")
/ / Append ( ") \ n")
. Append ( ") \ n")
. Append ( ")")
. Append ( "</ script> \ n")
. Append ( "");
Html.append ( "<table border=0 cellspacing=0 cellpadding=0 align=center width=80%> \ n")
.append( ” <tr> \n”)
. Append ( "<td align=left>
\ N ");
Html.append ( "total"). Append (getTotalPageCount ()). Append ( "pages")
. Append ( "["). Append (getStart ()). Append (".."). append (getEnd ())
. Append ("/"). append (this.getTotalSize ()). Append ( "] \ n")
. Append ( "</ td> \ n")
. Append ( "<td align=right> \ n");
If (hasPreviousPage ()) (
Html.append ( "[. Append ("("). Append (getCurrentPageNo () -1)
. Append ( ") '> previous] \ n");
)
Html.append ( "")
. Append ( "<select name = '")
.append(pageNoParamName).append(”‘ onChange=’javascript:”)
.append(gotoPage).append(”(this.value)’> \ N ");
String selected = "selected";
For (int i = 1; i <= getTotalPageCount (); i + +) (
If (i == getCurrentPageNo ())
Selected = "selected";
Else selected = "";
Html.append ( "<='"). append option value (i). Append (" ' ")
.append(selected).append(”> "). Append (i). Append (" </ option> \ n ");
)
If (getCurrentPageNo ()> getTotalPageCount ()) (
Html.append ( "<='"). append option value (getCurrentPageNo ())
.append(”‘ selected> "). Append (getCurrentPageNo ())
. Append ( "</ option> \ n");
)
Html.append ( "</ select> page \ n");
If (hasNextPage ()) (
Html.append ( "[. Append ("("). append ((getCurrentPageNo () +1))
. Append ( ") '> Next] \ n");
)
Html.append ( "</ td> </ tr> </ table> \ n");
Return html.toString ();
)
)
///////////////////////////////////
/ /
/ / RowSetPage.java
/ / Author: evan_zhao@hotmail.com
/ /
///////////////////////////////////
Package page;
Import javax.sql.RowSet;
/ **
*
Title: RowSetPage
*
Description: Use data paging RowSet objects Packaging
*
Copyright: Copyright (c) 2003
* @ Author evan_zhao@hotmail.com
* @ Version 1.0
* /
Public class RowSetPage extends Page (
Private javax.sql.RowSet rs;
/ **
* Empty page
* /
Public static final RowSetPage EMPTY_PAGE = new RowSetPage ();
/ **
* The default constructor, creating an empty page
* /
Public RowSetPage () (
This (null, 0,0);
)
/ **
* Constructors paging object
* @ Param crs contains a data OracleCachedRowSet
* @ Param start page data in the database in the initial position
* @ Param totalSize database contains the records of the total number of
* /
Public RowSetPage (RowSet crs, int start, int totalSize) (
This (crs, start, totalSize, Page.DEFAULT_PAGE_SIZE);
)
/ **
* Constructors paging object
* @ Param crs contains a data OracleCachedRowSet
* @ Param start page data in the database in the initial position
* @ Param totalSize database contains the records of the total number of
* @ PageSize page to accommodate the record number
* /
Public RowSetPage (RowSet crs, int start, int totalSize, int pageSize) (
Try (
Int avaCount = 0;
If (crs! = Null) (
Crs.beforeFirst ();
If (crs.next ()) (
Crs.last ();
AvaCount = crs.getRow ();
)
Crs.beforeFirst ();
)
Rs = crs;
Super.init (start, avaCount, totalSize, pageSize, rs);
) Catch (java.sql.SQLException sqle) (
Throw new RuntimeException (sqle.toString ());
)
)
/ **
* Paging object from the data records
* /
Public javax.sql.RowSet getRowSet () (
Return rs;
)
)
///////////////////////////////////
/ /
/ / PagedStatement.java
/ / Author: evan_zhao@hotmail.com
/ /
///////////////////////////////////
Package page;
Import foo.DBUtil;
Import java.math.BigDecimal;
Import java.util.List;
Import java.util.Iterator;
Import java.util.Collections;
Import java.sql.Connection;
Import java.sql.SQLException;
Import java.sql.ResultSet;
Import java.sql.Statement;
Import java.sql.PreparedStatement;
Import java.sql.Timestamp;
Import javax.sql.RowSet;
/ **
*
Title: Paging enquiries
*
Description: According to a query on the page and the page data
*
Copyright: Copyright (c) 2002
* @ Author evan_zhao@hotmail.com
* @ Version 1.0
* /
(Public abstract class PagedStatement
Public final static int MAX_PAGE_SIZE = Page.MAX_PAGE_SIZE;
Protected String countSQL, querySQL;
Protected int pageNo, pageSize, startIndex, totalCount;
Protected javax.sql.RowSet rowSet;
Protected RowSetPage rowSetPage;
Private List boundParams;
/ **
* Constructors enquiries from all data PageStatement
* @ Param sql query sql
* /
Public PagedStatement (String sql) (
This (sql, 1, MAX_PAGE_SIZE);
)
/ **
* When a structure for a page of data PageStatement
* @ Param sql query sql
* @ Param pageNo page
* /
Public PagedStatement (String sql, int pageNo) (
This (sql, pageNo, Page.DEFAULT_PAGE_SIZE);
)
/ **
* When a structure for a page PageStatement data, and specify the number of records per page
* @ Param sql query sql
* @ Param pageNo page
* @ Param pageSize page capacity
* /
Public PagedStatement (String sql, int pageNo, int pageSize) (
This.pageNo = pageNo;
This.pageSize = pageSize;
This.startIndex = Page.getStartOfAnyPage (pageNo, pageSize);
Collections.synchronizedList this.boundParams = (new java.util.LinkedList ());
This.countSQL = "select count (*) from (" sql + + ")";
This.querySQL = intiQuerySQL (sql, this.startIndex, pageSize);
)
/ **
* Generation for a data sql statement
* @ Param sql original query
* @ StartIndex begin recording location
* @ Size needed to get the record number
* /
Protected abstract String intiQuerySQL (String sql, int startIndex, int size);
/ **
* Use the object is the value of parameter settings specified
* @ Param index for a first parameter, and the second for 2. . .
* @ Param obj the object contains parameters
* /
Public void setObject (int index, Object obj) (throws SQLException
BoundParam bp = new BoundParam (index, obj);
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use the object is the value of parameter settings specified
* @ Param index for a first parameter, and the second for 2. . .
* @ Param obj the object contains parameters
* @ Param targetSqlType parameters of the database type
* /
Public void setObject (int index, Object obj, int targetSqlType) throws SQLException (
BoundParam bp = new BoundParam (index, obj, targetSqlType);
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use the object is the value of parameter settings specified
* @ Param index for a first parameter, and the second for 2. . .
* @ Param obj the object contains parameters
* @ Param targetSqlType parameters of the database type (constants defined in the java.sql.Types)
* @ Param scale accuracy, the median after the decimal point
* (Only targetSqlType Types.NUMBER or Types.DECIMAL is effective, while ignoring other types)
* /
Public void setObject (int index, Object obj, int targetSqlType, int scale) throws SQLException (
BoundParam bp = new BoundParam (index, obj, targetSqlType, scale);
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use the string is the value of parameter settings specified
* @ Param index for a first parameter, and the second for 2. . .
* @ Param str parameter contains the string value
* /
Public void setString (int index, String str) (throws SQLException
BoundParam bp = new BoundParam (index, str);
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use the string is the value of parameter settings specified
* @ Param index for a first parameter, and the second for 2. . .
* @ Param timestamp value of the parameters contain timestamps
* /
Public void setTimestamp (int index, Timestamp timestamp) throws SQLException (
BoundParam bp = new BoundParam (index, timestamp);
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use given integer parameter settings specified value
* @ Param index for a first parameter, and the second for 2. . .
* @ Param value contains integer parameter values
* /
Public void setInt (int index, int value) throws SQLException (
BoundParam bp = new BoundParam (index, new Integer (value));
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use is a long integer value of the parameter settings specified
* @ Param index for a first parameter, and the second for 2. . .
* @ Param value includes the value of long integer parameters
* /
Public void setLong (int index, long value) (throws SQLException
BoundParam bp = new BoundParam (index, the new Long (value));
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use double-precision floating point numbers are designated parameter values set
* @ Param index for a first parameter, and the second for 2. . .
* @ Param value of the parameter values include double-precision floating-point
* /
Public void setDouble (int index, the double value) throws SQLException (
BoundParam bp = new BoundParam (index, the new Double (value));
BoundParams.remove (bp);
BoundParams.add (bp);
)
/ **
* Use BigDecimal given set of parameters specified value
* @ Param index for a first parameter, and the second for 2. . .
* @ Param bd value of the BigDecimal contains parameters
* /
Public void setBigDecimal (int index, BigDecimal bd) throws SQLException (
BoundParam bp = new BoundParam (index, bd);
BoundParams.remove (bp);
BoundParams.add (bp);
)
Private void setParams (PreparedStatement pst) throws SQLException (
If (pst == null | | this.boundParams == null | | this.boundParams.size () == 0) return;
BoundParam param;
For (Iterator itr = this.boundParams.iterator (); itr.hasNext ();){
Param = (BoundParam) itr.next ();
If (param == null) continue;
If (param.sqlType == java.sql.Types.OTHER) (
Pst.setObject (param.index, param.value);
Else ()
Pst.setObject (param.index, param.value, param.sqlType, param.scale);
)
)
)
/ **
* Implementation of a data queries, after the closure of the implementation of the database connection
* @ Return RowSetPage
* @ Throws SQLException
* /
Public RowSetPage executeQuery () (throws SQLException
System.out.println ( "executeQueryUsingPreparedStatement");
Connection conn = DBUtil.getConnection ();
PreparedStatement pst = null;
ResultSet rs = null;
Try (
Pst = conn.prepareStatement (this.countSQL);
SetParams (pst);
Rs = pst.executeQuery ();
If (rs.next ()) (
Rs.getInt totalCount = (1);
Else ()
TotalCount = 0;
)
Rs.close ();
Pst.close ();
If (totalCount <1) return RowSetPage.EMPTY_PAGE;
Pst = conn.prepareStatement (this.querySQL);
System.out.println (querySQL);
Pst.setFetchSize (this.pageSize);
SetParams (pst);
Rs = pst.executeQuery ();
/ / Rs.setFetchSize (pageSize);
This.rowSet = populate (rs);
Rs.close ();
Rs = null;
Pst.close ();
Pst = null;
This.rowSetPage = new RowSetPage (this.rowSet, startIndex, totalCount, pageSize);
Return this.rowSetPage;
) Catch (SQLException sqle) (
/ / System.out.println ( "executeQuery SQLException");
Sqle.printStackTrace ();
Throw sqle;
) Catch (Exception e) (
E.printStackTrace ();
Throw new RuntimeException (e.toString ());
Finally ()
/ / System.out.println ( "executeQuery finally");
DBUtil.close (rs, pst, conn);
)
)
/ **
* ResultSet data will be filled into CachedRowSet
* /
Protected abstract RowSet populate (ResultSet rs) throws SQLException;
/ **
* Packaging from query results into RowSet
* @ Return RowSet
* /
Public javax.sql.RowSet getRowSet () (
Return this.rowSet;
)
/ **
* Packaging from the query results into RowSetPage
* @ Return RowSetPage
* /
Public RowSetPage getRowSetPage () (
Return this.rowSetPage;
)
/ **
* Close Database Connection
* /
Public void close () (
/ / Database connection because in the end enquiries or anomalies that closed here do nothing
/ / Left to expand.
)
(Private class BoundParam
Int index;
Object value;
Int sqlType;
Int scale;
Public BoundParam (int index, Object value) (
This (index, value, java.sql.Types.OTHER);
)
Public BoundParam (int index, Object value, int sqlType) (
This (index, value, sqlType, 0);
)
Public BoundParam (int index, Object value, int sqlType, int scale) (
This.index = index;
This.value = value;
This.sqlType = sqlType;
This.scale = scale;
)
Public boolean equals (Object obj) (
If (obj! = Null & this.getClass (). IsInstance (obj)) (
BoundParam bp = (BoundParam) obj;
If (this.index == bp.index) return true;
)
Return false;
)
)
)
///////////////////////////////////
/ /
/ / PagedStatementOracleImpl.java
/ / Author: evan_zhao@hotmail.com
/ /
///////////////////////////////////
Package page;
Import java.sql.ResultSet;
Import java.sql.SQLException;
Import javax.sql.RowSet;
Import oracle.jdbc.rowset.OracleCachedRowSet;
/ **
*
Title: tabbed for Oracle Database
*
Copyright: Copyright (c) 2002
* @ Author evan_zhao@hotmail.com
* @ Version 1.0
* /
Public class PagedStatementOracleImpl extends PagedStatement (
/ **
* Constructors enquiries from all data PageStatement
* @ Param sql query sql
* /
Public PagedStatementOracleImpl (String sql) (
Super (sql);
)
/ **
* When a structure for a page of data PageStatement
* @ Param sql query sql
* @ Param pageNo page
* /
Public PagedStatementOracleImpl (String sql, int pageNo) (
Super (sql, pageNo);
)
/ **
* When a structure for a page PageStatement data, and specify the number of records per page
* @ Param sql query sql
* @ Param pageNo page
* @ Param pageSize page capacity
* /
Public PagedStatementOracleImpl (String sql, int pageNo, int pageSize) (
Super (sql, pageNo, pageSize);
)
/ **
* Generation for a data sql statement
* @ Param sql original query
* @ StartIndex begin recording location
* @ Size needed to get the record number
* /
Protected String intiQuerySQL (String sql, int startIndex, int size) (
StringBuffer querySQL = new StringBuffer ();
If (size! = Super.MAX_PAGE_SIZE) (
QuerySQL.append ( "select * from (select my_table .*, rownum as my_rownum from (")
. Append (sql)
. Append ( ") my_table where rownum <"). Append (startIndex + size)
. Append ( ") where my_rownum >="). append (startIndex);
Else ()
QuerySQL.append ( "select * from (select my_table .*, rownum as my_rownum from (")
. Append (sql)
. Append ( ") my_table")
. Append ( ") where my_rownum >="). append (startIndex);
)
Return querySQL.toString ();
)
/ **
* ResultSet data will be filled into CachedRowSet
* /
Protected RowSet populate (ResultSet rs) throws SQLException (
OracleCachedRowSet ocrs = new OracleCachedRowSet ();
Ocrs.populate (rs);
Return ocrs;
)
)
This paper quoted a circular Address: http://blog.csdn.net/wanchao2001/services/trackbacks/460066.aspx
Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr>
↑ Back
Web application packaging steps
Abstract: web application packaging steps
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle">
Web application packaging steps:
1. Build web applications, directory, as follows:
D: \ Tomcat 5.0 \ webapps \ netcard \ *. jsp (JSP documents directory)
D: \ Tomcat 5.0 \ webapps \ netcard \ WEB-INF \ classes \ *. class (class files directory)
D: \ Tomcat 5.0 \ webapps \ netcard \ WEB-INF \ classes \ *. jar (Class document directory)
D: \ Tomcat 5.0 \ webapps \ netcard \ WEB-INF \ classes \ web.xml (web application deployment)
<table Width="676" border="0"> <tr> <td width="396">
2. Jar with orders to the web application package:
D: \> cd Tomcat 5.0 \ webapps \ netcard
D: \ Tomcat 5.0 \ webapps \ netcard> jar cvf netcard.war *.*
One - the creation of a new document c
- V generate detailed output to standard output,
- F archive file name specified
3. Copy of the document to netcard.war
Directory (for testing)
4. Delete the original directory netcard
5. Start tomcat server
6.http: / / localhost: 8080/netcard/index.jsp test!
</ Td> <td width="270" align="center"> </ td> </ tr> </ table>
</ Td> </ tr> <tr>
↑ Back
Properties file for use with mysql database connection pool proxool
Abstract: The paper attributes assigned to mysql database connection pool proxool
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle">
1, to write a document attributes: Proxool.properties, Add to your application's WEB WEB-INF \ classes below, as follows:
Jdbc-0.proxool.alias = mysql
Jdbc-0.proxool.driver-class = org.gjt.mm.mysql.Driver
Jdbc-0.proxool.driver-url = jdbc: mysql: / / localhost: 3306/soft? User = root & password =
<table Width="673" border="0"> <tr> <td width="387"> PropertyFile WEB-INF/classes/Proxool.properties
Jdbc-0.proxool.maximum-connection-count = 20
Jdbc-0.proxool.prototype-count = 4
Jdbc-0.proxool.house-keeping-test-sql = select CURRENT_DATE
Jdbc-0.proxool.verbose = true
Jdbc-0.proxool.statistics = 10s, 1m, 1d
Jdbc-0.proxool.statistics-log-level = DEBUG
2, so write web.xml:
<? Xml version = "1.0" encoding = "ISO-8859-1">
Web-app
PUBLIC "- / / Sun Microsystems, Inc / / DTD Web Application 2.3 / / EN"
"Http://java.sun.com/dtd/web-app_2_3.dtd">
</ Td> <td width="276"> </ td> </ tr> </ table>
3, will be the driving procedures mm.mysql-2.0.14-bin.jar and proxool-0.8.3.jar Add WEB-INF \ lib directory.
4, Below is the test jsp documents:
<% @ Page import = "java.sql .*"%>
<% @ Page contentType = "text / html; charset = GB2312"%>
<head>
</ Head>
<body>
Use Proxool Connection Pool
<%
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Try (
Con = DriverManager.getConnection ( "proxool.mysql");
Stmt = con.createStatement ();
String query = "select * from count_num";
Rs = stmt.executeQuery (query);
While (rs.next ()) (
Out.print (rs.getLong (1 )+"– OK ");
)
Stmt.close ();
Con.close ();
) Catch (SQLException sqle) (
Out.println ( "sqle =" + sqle);
)
Finally (
Try (
If (con! = Null) (
Con.close ();
)
) Catch (SQLException sqle) (
Out.println ( "sqle =" + sqle);
)
)
%>
</ Body>
5, statistics and background information
Please go to: http://127.0.0.1:8080/testpxool/Admin
(Testpxool should read your application WEB) </ td> </ tr> <tr>
↑ Back
Lianliankan code (basic algorithm) plus some of Notes
Abstract: Lianliankan code (basic algorithm) plus some of Notes
From: Stroll resources Station
Import java.awt .*;
Import java.awt.event .*;
Public class lianliankan implements ActionListener
(
Static String s = "no" / / click of a button to record information
Int x0 = 0, y0 = 0, x = 0, y = 0, n1 = 0, n2 = 0; / / button to record the location information
Frame f and f1;
Button b1, b2, b3, b4, b5, b6, b7, b8, b9, b10; / / method relatively stupid added
Button b11, b12, b13, b14, b15, b16, b17, b18; / / 30 button interface to achieve games
Button b19, b20, b21, b22, b23, b24, b25; / / array can be used to achieve, and this is my
Button b26, b27, b28, b29, b30, bc; / / of java, entry link,
Button b, ba, br, bt1, bt2; / / Some things Amateur! ! Hee hee
Panel p1, p2, and p3;
TextField t; / / used to show some random information, the following method is guli ().
Label l;
Int d [][]={ / / and the interface used to establish the button mapping relations
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0) (
);
Public static void main (String [] args)
(
Lianliankan t = new lianliankan ();
T.suiji ();
T.go ();
)
Public void actionPerformed (ActionEvent e) / / button again incident response.
(
Int d [][]={
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0) (
);
This.d = d;
Suiji ();
F.setVisible (false);
F1.setVisible (false);
S = "no";
Go ();
)
Public void go () / / initialization interface
(
L = new Label ( "Dear audience,");
F = new Frame ( "Lianliankan");
T = new TextField ();
P2 = new Panel ();
P1 = new Panel ();
P3 = new Panel ();
Bc = new Button ( "Exit");
Br = new Button ( "Restated");
B = new Button ();
B1 = new Button (String.valueOf (d [1] [1]));
B2 = new Button (String.valueOf (d [1] [2]));
B3 = new Button (String.valueOf (d [1] [3]));
B4 = new Button (String.valueOf (d [1] [4]));
B5 = new Button (String.valueOf (d [1] [5]));
B6 = new Button (String.valueOf (d [2] [1]));
B7 = new Button (String.valueOf (d [2] [2]));
B8 = new Button (String.valueOf (d [2] [3]));
B9 = new Button (String.valueOf (d [2] [4]));
B10 = new Button (String.valueOf (d [2] [5]));
B11 = new Button (String.valueOf (d [3] [1]));
B12 = new Button (String.valueOf (d [3] [2]));
B13 = new Button (String.valueOf (d [3] [3]));
B14 = new Button (String.valueOf (d [3] [4]));
B15 = new Button (String.valueOf (d [3] [5]));
B16 = new Button (String.valueOf (d [4] [1]));
B17 = new Button (String.valueOf (d [4] [2]));
B18 = new Button (String.valueOf (d [4] [3]));
B19 = new Button (String.valueOf (d [4] [4]));
B20 = new Button (String.valueOf (d [4] [5]));
B21 = new Button (String.valueOf (d [5] [1]));
B22 = new Button (String.valueOf (d [5] [2]));
B23 = new Button (String.valueOf (d [5] [3]));
B24 = new Button (String.valueOf (d [5] [4]));
B25 = new Button (String.valueOf (d [5] [5]));
B26 = new Button (String.valueOf (d [6] [1]));
B27 = new Button (String.valueOf (d [6] [2]));
B28 = new Button (String.valueOf (d [6] [3]));
B29 = new Button (String.valueOf (d [6] [4]));
B30 = new Button (String.valueOf (d [6] [5]));
P3.setLayout (null);
P1.setSize (250,300);
P2.setSize (100,40);
P3.setSize (300,30);
T.setSize (60,30);
L.setSize (70,30);
P1.setLayout (new GridLayout (6,5));
P1.setBackground (Color.pink);
P1.setLocation (100, 100);
P2.setLocation (0,400);
P3.setLocation (50,50);
T.setLocation (230,2);
L.setLocation (150,2);
Bc.setLocation (0,40);
Br.setLocation (0, 100);
F.add (p1);
F.add (p2);
F.add (p3);
P3.add (l);
P3.add (t);
P2.add (bc);
P2.add (br);
P1.add (b1);
P1.add (b2);
P1.add (b3);
P1.add (b4);
P1.add (b5);
P1.add (b6);
P1.add (b7);
P1.add (b8);
P1.add (b9);
P1.add (b10);
P1.add (b11);
P1.add (b12);
P1.add (b13);
P1.add (b14);
P1.add (b15);
P1.add (b16);
P1.add (b17);
P1.add (b18);
P1.add (b19);
P1.add (b20);
P1.add (b21);
P1.add (b22);
P1.add (b23);
P1.add (b24);
P1.add (b25);
P1.add (b26);
P1.add (b27);
P1.add (b28);
P1.add (b29);
P1.add (b30);
F.pack ();
F.setBounds (280,100,500,450);
F.setResizable (false);
F.setVisible (true);
Bc.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Ex ();
)
));
Br.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Chonglie ();
)
));
B1.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (1,1, b1);
)
));
B2.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (1,2, b2);
)
));
B3.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (1,3, b3);
)
));
B4.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (1,4, b4);
)
));
B5.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (1,5, b5);
)
));
B6.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (2,1, b6);
)
));
B7.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (2,2, b7);
)
));
B8.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (2,3, b8);
)
));
B9.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (2,4, b9);
)
));
B10.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (2,5, b10);
)
));
B11.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (3,1, b11);
)
));
B12.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (3,2, b12);
)
));
B13.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (3,3, b13);
)
));
B14.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (3,4, b14);
)
));
B15.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (3,5, b15);
)
));
B16.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (4,1, b16);
)
));
B17.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (4,2, b17);
)
));
B18.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (4,3, b18);
)
));
B19.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (4,4, b19);
)
));
B20.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (4,5, b20);
)
));
B21.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (5,1, b21);
)
));
B22.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (5,2, b22);
)
));
B23.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (5,3, b23);
)
));
B24.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (5,4, b24);
)
));
B25.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (5,5, b25);
)
));
B26.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (6,1, b26);
)
));
B27.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (6,2, b27);
)
));
B28.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (6,3, b28);
)
));
B29.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (6,4, b29);
)
));
B30.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
Wei (6,5, b30);
)
));
)
Public void ex () / / exit interface, available diolog to achieve the type of model, more in line with
(
F1 = new Frame ( "Gaming operations");
F1.setLayout (new GridLayout (1,1));
Bt1 = new Button ( "set out");
Bt2 = new Button ( "and then a");
F1.add (bt1);
F1.add (bt2);
F1.pack ();
F1.setBounds (400,250,90,60);
F1.setResizable (false);
F1.show ();
F1.setVisible (true);
Bt1.addMouseListener (new MouseAdapter () (
Public void mouseClicked (MouseEvent e)
(
System.exit (0);
)
));
Bt2.addActionListener (this);
)
Public void suiji () / / generated random numbers, the game interface corresponding to fill the various positions of the array
(
Int m, n, k = 0, k1, k2, k3;
For (m = 1, m <= 15; m + +)
(
K1 = (int) (Math.random () * 25 +1);
For (n = 1, n <= 2, n + +)
(
K2 = (int) (Math.random () * 6 +1);
K3 = (int) (Math.random () * 5 +1);
While (d [k2] [k3]! = 0 & & k! = 30)
(
K2 = (int) (Math.random () * 6 +1);
K3 = (int) (Math.random () * 5 +1);
)
This.d [k2] [k3] = k1;
K + +;
)
)
)
Public void guli () / / random information
(
Int l = 0;
T.setText ("");
L = (int) (Math.random () * 10);
System.out.println (l);
Switch (l)
(
Case 1:
T.setText ( "Good! Come on!");
Break;
Case 3:
T.setText ( "You terrific!");
Break;
Case 5:
T.setText ( "speed up the pace!");
Break;
Case 6:
T.setText ( "Yes ah!");
Break;
Case 8:
T.setText ( "Come on!");
Break;
Case 9:
T.setText ( "smart enough!");
Break;
Default:
Break;
)
)
Public void chonglie () / / Restated method
(
Int save [], i, j, n = 0, k2, k3, k;
Int d [][]={
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0 (),
0,0,0,0,0,0,0) (
);
Save = new int [30];
For (n = 0; n <30; n + +)
Save [n] = 0; / / definition of an array to store the current location of each button on the information
N = 0;
For (i = 0; i <= 6; i + +)
For (j = 0; j <= 5; j + +)
(
If (this.d [i] [j]! = 0)
(
Save this.d [n] = [i] [j];
N + +;
)
)
N = n-1;
This.d = d;
While (n> = 0) / / a random location, placed buttons
(
K2 = (int) (Math.random () * 6 +1);
K3 = (int) (Math.random () * 5 +1);
While (d [k2] [k3]! = 0)
(
K2 = (int) (Math.random () * 6 +1);
K3 = (int) (Math.random () * 5 +1);
)
This.d [k2] save [k3] = [n];
N -;
)
F.setVisible (false);
S = "no" / / button click here it must return the initial information
Go ();
Ling ();
)
Public void ling () / / will be members of the array to zero corresponding button elimination
(/ / Type of the array using the buttons will be streamlined to achieve much,
If (d [1] [1] == 0)
B1.setVisible (false);
If (d [1] [2] == 0)
B2.setVisible (false);
If (d [1] [3] == 0)
B3.setVisible (false);
If (d [1] [4] == 0)
B4.setVisible (false);
If (d [1] [5] == 0)
B5.setVisible (false);
If (d [2] [1] == 0)
B6.setVisible (false);
If (d [2] [2] == 0)
B7.setVisible (false);
If (d [2] [3] == 0)
B8.setVisible (false);
If (d [2] [4] == 0)
B9.setVisible (false);
If (d [2] [5] == 0)
B10.setVisible (false);
If (d [3] [1] == 0)
B11.setVisible (false);
If (d [3] [2] == 0)
B12.setVisible (false);
If (d [3] [3] == 0)
B13.setVisible (false);
If (d [3] [4] == 0)
B14.setVisible (false);
If (d [3] [5] == 0)
B15.setVisible (false);
If (d [4] [1] == 0)
B16.setVisible (false);
If (d [4] [2] == 0)
B17.setVisible (false);
If (d [4] [3] == 0)
B18.setVisible (false);
If (d [4] [4] == 0)
B19.setVisible (false);
If (d [4] [5] == 0)
B20.setVisible (false);
If (d [5] [1] == 0)
B21.setVisible (false);
If (d [5] [2] == 0)
B22.setVisible (false);
If (d [5] [3] == 0)
B23.setVisible (false);
If (d [5] [4] == 0)
B24.setVisible (false);
If (d [5] [5] == 0)
B25.setVisible (false);
If (d [6] [1] == 0)
B26.setVisible (false);
If (d [6] [2] == 0)
B27.setVisible (false);
If (d [6] [3] == 0)
B28.setVisible (false);
If (d [6] [4] == 0)
B29.setVisible (false);
If (d [6] [5] == 0)
B30.setVisible (false);
)
Public void wei (int w1, int w2, Button bz) / / judge and record the information for each click of a button
(/ / When the same two buttons can be deleted
If ((s.trim ()). Equals ( "no"))
(
S = b1.getLabel ();
X0 = w1;
Y0 = w2;
N1 = d [x0] [y0];
B = bz;
X = w1;
Y = w2;
N2 = d [x] [y];
Bz = ba;
)
Else
(
X0 = x;
Y0 = y;
N1 = d [x0] [y0];
B = ba;
X = w1;
Y = w2;
N2 = d [x] [y];
Bz = ba;
If (n1 = n2 & ba! = B)
(
Xiao ();
)
)
)
Public void xiao () / / This is the most important part of the game is judged two buttons in the information
(/ / The same circumstances can be deleted. A detailed analysis of different Clause Notes
Int i = 0, j = 0, n = 0, k = 0;
If ((x0 = x & & (y0 == y +1 | | y-y0 == 1)) | | ((x0 = x +1 | | x0 = x-1) & (y = y0 ))) / / adjacent situation
(
Ba.setVisible (false);
B.setVisible (false);
Guli ();
S = "no";
D [x0] [y0] = 0;
D [x] [y] = 0;
)
Else
(
For (j = 0; j <7; j + +) / / 2 line of button, whether or not they can eliminate
(
If (d [x0] [j] == 0)
(
If (y> j)
(
For (i = y-1; i> = j; i -)
(
If (d [x] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 1;
)
)
If (k == 1)
(
If (y0> j)
(
For (i = y0-1; i> = j; i -)
(
If (d [x0] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
If (y0
For (i = y0 +1; i <= j; i + +)
(
If (d [x0] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
)
)
If (y
For (i = y +1; i <= j; i + +)
(
If (d [x] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 1;
)
)
If (k == 1)
(
If (y0> j)
(
For (i = y0-1; i> = j; i -)
(
If (d [x0] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
If (y0
For (i = y0 +1; i <= j; i + +)
(
If (d [x0] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
)
)
If (y == j)
(
If (y0> j)
(
For (i = y0-1; i> = j; i -)
(
If (d [x0] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
If (y0
For (i = y0 +1; i <= j; i + +)
(
If (d [x0] [i]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
)
)
If (k == 2)
(If (x == x0)
(
B.setVisible (false);
Ba.setVisible (false);
Guli ();
S = "no";
K = 0;
D [x0] [y0] = 0;
D [x] [y] = 0;
)
If (x0
For (n = x0; n <= x-1, n + +)
(
If (d [n] [j]! = 0)
(
K = 0;
Break;
)
If (d [n] [j] == 0 & & n = x-1)
(
B.setVisible (false);
Ba.setVisible (false);
Guli ();
S = "no";
K = 0;
D [x0] [y0] = 0;
D [x] [y] = 0;
)
)
)
If (x0> x)
(
For (n = x0; n> = x +1, n -)
(
If (d [n] [j]! = 0)
(
K = 0;
Break;
)
If (d [n] [j] == 0 & & n = x +1)
(
B.setVisible (false);
Ba.setVisible (false);
Guli ();
S = "no";
K = 0;
D [x0] [y0] = 0;
D [x] [y] = 0;
)
)
)
)
)
For (i = 0; i <8; i + +) / / set out by analysis of whether we can eliminate
(
If (d [i] [y0] == 0)
(
If (x> i)
(
For (j = x-1; j> = i; j -)
(
If (d [j] [y]! = 0)
(
K = 0;
Break;
)
Else
(
K = 1;
)
)
If (k == 1)
(
If (x0> i)
(
For (j = x0-1; j> = i; j -)
(
If (d [j] [y0]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
If (x0 (
For (j = x0 +1; j <= i; j + +)
(
If (d [j] [y0]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
)
)
If (x (
For (j = x +1; j <= i; j + +)
(
If (d [j] [y]! = 0)
(
K = 0;
Break;
)
Else
(
K = 1;
)
)
If (k == 1)
(
If (x0> i)
(
For (j = x0-1; j> = i; j -)
(
If (d [j] [y0]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
If (x0 (
For (j = x0 +1; j <= i; j + +)
(
If (d [j] [y0]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
)
)
If (x == i)
(
If (x0> i)
(
For (j = x0-1; j> = i; j -)
(
If (d [j] [y0]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
If (x0 (
For (j = x0 +1; j <= i; j + +)
(
If (d [j] [y0]! = 0)
(
K = 0;
Break;
)
Else
(
K = 2;
)
)
)
)
)
If (k == 2)
(
If (y = y0)
(
B.setVisible (false);
Ba.setVisible (false);
Guli ();
S = "no";
K = 0;
D [x0] [y0] = 0;
D [x] [y] = 0;
)
If (y0
For (n = y0; n <= y-1, n + +)
(
If (d [i] [n]! = 0)
(
K = 0;
Break;
)
If (d [i] [n] == 0 & & y-n == 1)
(
B.setVisible (false);
Ba.setVisible (false);
Guli ();
S = "no";
K = 0;
D [x0] [y0] = 0;
D [x] [y] = 0;
)
)
)
If (y0> y)
(
For (n = y0; n> = y +1, n -)
(
If (d [i] [n]! = 0)
(
K = 0;
Break;
)
If (d [i] [n] == 0 & & n == y +1)
(
B.setVisible (false);
Ba.setVisible (false);
Guli ();
S = "no";
K = 0;
D [x0] [y0] = 0;
D [x] [y] = 0;
)
)
)
)
)
)
)
)
↑ Back
Html-formatted messages sent
Abstract: Send mail html format
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> my mailbox is Sina, e-mail SMTP authentication required by the following documentation JavaMail.html JavaMail.jsp sent with the success!
(Environment: Tomcat 5.016, the package is needed and activation.jar mail.jar put on your application's WEB WEB-INF/lib directory)
JavaMail.html collect information
<head>
</ Head>
<body>
JavaMail use to send e-mail - HTML format
<form Name="SendMessage" Method="post" action="JavaMail.jsp">
Sender: <input type = "text" name = "From" size = "30" maxlength = "30">
Addressee: <input type = "text" name = "To" size = "30" maxlength = "30">
Subject: <input type = "text" name = "Subject" size = "30" maxlength = "30">
Format: <select name = "Type" size = "1">
<option Value="text/plain"> Text </ option>
<option Value="text/html"> HTML </ option>
</ Select>
:
<textarea Name="Message" cols=40 rows=5> </ textarea>
<input Type="submit" value="å‘é€">
<input Type="reset" value="é‡å¡«">
</ Form>
</ Body>
<table Width="676" border="0"> <tr> <td width="394"> JavaMail.jsp email
<% @ Page import = "javax.mail .*"%>
<% @ Page import = "javax.activation .*"%>
<% @ Page import = "javax.mail.internet .*"%>
<% @ Page import = "java.util .*, java.io. *"%>
<% @ Page contentType = "text / html; charset = GB2312"%>
<head>
</ Head>
<body>
JavaMail use to send e-mail - HTML format
</ Td> <td width="272"> </ td> </ tr> </ table>
<%
InternetAddress address [] = null;
Request.setCharacterEncoding ( "gb2312");
String mailserver = "smtp.sina.com.cn";
String From = request.getParameter ( "From");
String to = request.getParameter ( "To");
String Subject = request.getParameter ( "Subject");
String type = request.getParameter ( "Type");
String messageText = request.getParameter ( "Message");
Boolean sessionDebug = false;
Try (
/ / Set by the server and use the Mail Transfer Protocol used by the
Java.util.Properties props = System.getProperties ();
Props.put ( "mail.host" mailserver);
Props.put ( "mail.transport.protocol", "smtp");
Props.put ( "mail.smtp.auth", "true ");// specified the need for SMTP Authentication
/ / Create new services Session
Javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance (props, null);
MailSession.setDebug (sessionDebug);
Message msg = new MimeMessage (mailSession);
/ / Set of e-mail
Msg.setFrom (new InternetAddress (From));
/ / Set the recipient's mailbox
Address = InternetAddress.parse (to, false);
Msg.setRecipients (Message.RecipientType.TO, address);
/ / Set the theme of the letter
Msg.setSubject (Subject);
/ / Set the time messenger
Msg.setSentDate (new Date ());
Multipart mp = new MimeMultipart ();
MimeBodyPart mbp = new MimeBodyPart ();
/ / Set for the type of message content, text / plain or text / html
Mbp.setContent (messageText, type + "; charset = GB2312");
Mp.addBodyPart (mbp);
Msg.setContent (mp);
Transport transport = mailSession.getTransport ( "smtp");
/ / / / Please enter your e-mail user name and password, not to use my ^ _ ^
Transport.connect (mailserver, "zz3zcwb", "1234567");
Transport.sendMessage (msg, msg.getAllRecipients ());
Transport.close ();
/ / Transport.send (msg);
Out.println ( "e-mail has been successfully sent");
)
Catch (MessagingException mex)
(
Mex.printStackTrace ();
Out.println (mex);
)
%>
</ Body>
If you are successful, do not forget to e-mail me ah! ! Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr>
↑ Back
In the MS SQL server2000 call in the creation and storage process
Abstract: MS SQL server2000 call in the creation and storage process
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <% –
Date :2004-06-04
Please msbase.jar, mssqlserver.jar, msutil.jar three documents Add to Tomcat 5 \ common \ lib directory or your application's WEB-INF \ lib, and then MS SQL server2000 create databases and tables testjddbc myBook.
–%>
<table Width="684" border="0"> <tr> <td width="408"> <% @ page contentType = "text / html; charset = GB2312"%>
<% @ Page language = "java" import = "java.sql .*"%>
<%
String url =
"Jdbc: microsoft: sqlserver: / / localhost: 1433; DatabaseName = testjdbc";
String user = "sa";
String password = "";
Try (
Class.forName ( "com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection (url, user, password);
Statement stmt = conn.createStatement ();
Stmt = conn.createStatement ();
/ / Create a stored procedure can only run
</ Td> <td width="266"> </ td> </ tr> </ table>
/ * String createProc = "CREATE PROCEDURE INSERT_NANE_EMAIL" +
"@ NAME VARCHAR (30), @ Email VARCHAR (50)" +
"AS INSERT INTO myBook" +
"(Name, Email)" +
"VALUES" +
"(@ NAME, @ Email)";
Stmt.executeUpdate (createProc);
Out.println ( "create OK"); * /
CallableStatement cs = conn.prepareCall ( "(call INSERT_NANE_EMAIL (?,?)}");
Cs.setString (1, "CHEN WEI BO");
Cs.setString (2, "zz3zcwb@sina.com");
Cs.executeUpdate ();
Out.println ( "insert OK");
ResultSet rs = stmt.executeQuery ( "select * from myBook");
While (rs.next ()) (
Out.print (rs.getString (1) + "
");
Out.print (rs.getString (2) + "
");
)
) Catch (ClassNotFoundException e) (
Out.println (e);
)
Catch (SQLException e) (
Out.println (e);
)
%>
</ Td> </ tr> <tr>
↑ Back
[QQ Lianliankan imitate ideas:
Abstract: imitate QQ Lianliankan [ideas]
From: Stroll resources Station
Lianliankan the requirements of a directory of two arbitrary points can map a three connectivity solutions linking alerts Tip 4 5 6 props issue a map, the requirements of Lianliankan
1: To connect the two points on the graph are the same.
2: one does not exist between the two "obstacles" and pack no more than two points of the line.
So analysis can be seen, usually divided into three situations that [Legend]
Assumption of a two-dimensional array to a Lianliankan said that the map of elements in an array is 0 representatives of the game in the space of the interface, the value is greater than 0 representatives of the various games connect object (a representative of the stars, two representatives of Penguin)
Scenario 1: To connect the two points with a straight line
0 0 0 0 0 0
0 2 0 0 0 2 * *
0 0 0 0 0 0
Scenario 2: After a break point connected (+, the representative of Pack)
0 0 0 0 0 0
0 2 0 0 0 + + * ——
0 + 0 0 0 2 * + ——
(Two paths can be connected)
Case 3: After two discount points connected (for the penguins, that figure 2)
0 + 0 0 0 + 0 0 0 0 0 0
0 2 0 1 0 2 0 2 0 1 0 2
0 0 0 0 0 0 or 0 + 0 0 0 +
As an obstacle to this, so it is necessary to two packs can be connected two points, two points can arbitrarily connected Wayfinding algorithm is the core of the entire game algorithm. Implementation of the online version of many, this method is relatively easy, I understand that one way ^ o ^, but also hope that we can put forward their valuable comments and suggestions, I would like to thank the.
Thinking as follows:
1 2:00 a straight line can be linked to good judgement (a simple cycle judgement required)
2 Legend of the above two cases, the coordinates of discount points are fixed, that is, break point either
[1 point with the coordinates x, even y coordinates of the point 2] or [even the coordinates of a point y, and even the coordinates of points 2 x]
Y
|
|
| + * ——
| + —— *
—————- X
Therefore, we need only point a judge even be connected to the break point, and even to the point of two discount points that can be connected with point 1 and 2 can even point connectivity. And as a result break point and the two points are connected with a straight line, so can be easily judge concluded the first step.
3 situation into a situation of the three, (this step is the most impact on the algorithm performance and areas where improvement is needed)
How transformati