|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
一旦你有了思想,那你编的程序就有了灵魂,不管是什么语言到了你的手里都会是你的工具而已,他们的价值是能尽快帮助你实现你想要的目标。但是如果你没有了思想,那就像是海里的帆船失去了船帆,是很难到打海的另一边的。js|程序packageguestbook;
importjava.sql.*;
publicclassguestbook{
StringsDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
StringsConnStr="jdbc:odbc:guestbook";
Connectionconn=null;
ResultSetrs=null;
publicguestbook(){
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundExceptione){
System.err.println("guestbook():"+e.getMessage());
}
}
publicvoidexecuteInsert(Stringsql){
try{
conn=DriverManager.getConnection(sConnStr);
Statementstmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLExceptionex){
System.err.println("guestbook.executeUpdate:"+ex.getMessage());
}
}
publicResultSetexecuteQuery(Stringsql){
rs=null;
try{
conn=DriverManager.getConnection(sConnStr);
Statementstmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLExceptionex){
System.err.println("guestbook.executeQuery:"+ex.getMessage());
}
returnrs;
}
}
<html>
<head>
<title>MyFirstJspGuestBook</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<bodybgcolor="#CCCCFF"vlink="#000000"alink="#666666">
<divalign="center">
<p><fontsize="7"><b><fontsize="+6">JspGuestBook</font></b></font></p>
<formmethod="post"action="index.jsp">
<tablewidth="75%"align="center"border=1>
<tr>
<tdwidth="30%">
<divalign="right">Name:</div>
</td>
<tdwidth="70%">
<inputtype="text"name="name">
</td>
</tr>
<tr>
<tdwidth="30%">
<divalign="right">E-mail:</div>
</td>
<tdwidth="70%">
<inputtype="text"name="email">
</td>
</tr>
<tr>
<tdwidth="30%">
<divalign="right">SiteUrl:</div>
</td>
<tdwidth="70%">
<inputtype="text"name="url"value="http://">
</td>
</tr>
<tr>
<tdwidth="30%">
<p>Whatdoyouwantto</p>
<p>say?</p>
</td>
<tdwidth="70%">
<textareaname="body"rows="5"cols="30"></textarea>
</td>
</tr>
<tr>
<tdwidth="30%"></td>
<tdwidth="70%"></td>
</tr>
<tr>
<tdwidth="30%"></td>
<tdwidth="70%">
<tablewidth="75%">
<tr>
<td>
<inputtype="submit"name="send"value="Send">
</td>
<td>
<inputtype="reset"name="reset"value="Reset">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<hr>
<%@pagelanguage="java"import="java.sql.*" %>
<jsp:useBeanid="sqlbean"scope="page"class="guestbook.guestbook"/>
<%!Stringname,email,url,body,sql;%>
<%
if(name!=null&&email!=null&&body!=null)
{
name=request.getParameter("name");
email=request.getParameter("email");
url=request.getParameter("url");
body=request.getParameter("body");
sql="insertintoguestbook(Name,Email,Url,Body)
values("+name+","+email+","+url+","+body+")";
sqlbean.executeInsert(sql);
}else{
out.print("<b><fontcolor=red>Sorry,Pleaseenteryourname,emailandbody!!!</font></b>");
}
%>
<p><fontsize="4"><b><ahref="./index.jsp#see">SeeMyGuestbook</a></b></font></p>
<%--BecauseIdontkonwagoodmethodtokonwtheallitemscount,so....--%>
<%
// ResultSetRScount=sqlbean.executeQuery("SELECTcount(*)FROMguestbook");
ResultSetRScount=sqlbean.executeQuery("SELECT*FROMguestbook");
inti=0;
while(RScount.next()){
i++;
}
%>
<%--<p><aname=see><B>Now,<%=RScount%>Records.</B><a></p>--%>
<p><aname=see><B>Now,<%=i%>Records.</B><a></p>
<%
RScount.close();
i=0;
%>
<p></p>
<%
ResultSetRS=sqlbean.executeQuery("SELECT*FROMguestbookORDERBYRecordIDDESC");
while(RS.next()){
name=RS.getString("Name");
email=RS.getString("Email");
url=RS.getString("Url");
body=RS.getString("Body");
%>
<tableborder=1width=80%>
<tr>
<tdwidth=30%>Name:</td><tdwidth=70%><%=name%>
</tr>
<tr>
<tdwidth=30%>Email:</td><tdwidth=70%><ahref="mailto:<%=email%>"><%=email%></a></td>
</tr>
<tr>
<tdwidth=30%>SiteUrl:</td><tdwidth=70%><ahref="<%=url%>"><%=url%></a></td>
</tr>
<tr>
<tdwidth=30%>Body:</td><tdwidth=70%><%=body%></td>
</tr>
</table>
<hr>
<%
}
RS.close();
%>
</div>
</body>
</html>
java是一种面向对象的编程语言,优点是可移植性比较高,最初设计时就是本着一次编写到处执行设计的。可以开发各种应用程序和游戏,不过速度没有c++快,所以一般是不用java来编写应用程序和电脑游戏。 |
|