Jsp+mysql make a simple message board (4)

Source: Internet
Author: User
Tags count include mysql
Js|mysql for the message board, is to access the database, so opendata.jsp is essential.
<%
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
String URL
= "jdbc:mysql://localhost/mydate?user=root&password=zsliuyu&useunicode=true&characterencoding= GB2312 ";

Connection con=drivermanager.getconnection (URL);
Statement smt=con.createstatement ();
ResultSet rs;
String SQL;
%>
opendata.jsp;
Message board must keep the message in the database, connect the database, we will put the user's rumors into the database:
<%@ page import= "java.sql.*"%>
<%@ page import= "java.util.*"%>
<%@ include file= "opendata.jsp"%>
<%@ include file= "convert.jsp"%>
<%@ page contenttype= "text/html;charset=gb2312"%>
<%
String Name,email,subject,memo,sex;
Name=request.getparameter ("name");
Sex=request.getparameter ("Sex");
Email=request.getparameter ("email");
Subject=request.getparameter ("subject");
Memo=request.getparameter ("Memo");
if (Name.length () ==0| | Email.length () ==0| | Subject.length () ==0| | Memo.length () ==0)
{
Out.print ("<center><font color=red size=6> input field is not nullable </font>");
Out.print ("Out.print ("<a href=message.htm> I want to Message </a>");

}
Else
{
int COUNT=0,YEAR,MONTH,DAY,HOUR,MINUTE,SECOND,LASTP;
String time;
GregorianCalendar calendar;<%--use GregorianCalendar class to obtain time--%>
Calendar=new GregorianCalendar ();
Year=calendar.get (calendar.year);
Month=calendar.get (calendar.month) +1;
Day=calendar.get (Calendar.day_of_month);
Hour=calendar.get (Calendar.hour_of_day);
Minute=calendar.get (Calendar.minute);
Second=calendar.get (Calendar.second);
Time=year+ "The Year" +month+ "month" +day+ "the Day" +hour+ ":" +minute+ ":" +second;
Name=convert (name);
Time=convert (time);
Subject=convert (subject);
Memo=replace (Memo);
Memo=convert (Memo);
sql= INSERT INTO message set name= ' +name+ ', email= ' +email+ ', subject= ' "+subject+" ', Time= ' "+time+" ', sex= ' "+sex+" ' , memo= ' "+memo+" ";
Smt.executeupdate (SQL);
Sql= "SELECT * from Message";
Rs=smt.executequery (SQL);
while (Rs.next ())
count++;
lastp= (int) Math.ceil (double) COUNT/5);
Response.sendredirect ("board.jsp?pageno=" +LASTP);
}

%>
<title> error Message </title>

savememo.jsp
This program is used to deposit message.htm data into the database.




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.