每日打卡(一)
package com;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class Interface {
public boolean add( model){
String riqi =model.riqi();
String keyword =model.keyword();
String zongjie =model.zongjie();
String inday =model.inday();
String maxday =model.maxday();
Util db=new Util();
try {
String sql="INSERT INTO day(riqi,keyword,zongjie,inday,maxday) VALUES (?,?,?,?,?)";
Connection conn=db.getCon();
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, riqi);
ps.setString(2, keyword);
ps.setString(3, zongjie);
ps.setString(4, inday);
ps.setString(5, maxday);
ps.executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package com;public class model { private String riqi; private String keyword; private String zongjie; private String inday; private static String maxday; public String getRiqi() { return riqi; } public void setRiqi(String riqi) { this.riqi = riqi; } public String getKeyword() { return keyword; } public void setKeyword(String keyword) { this.keyword = keyword; } public String getZongjie() { return zongjie; } public void setZongjie(String zongjie) { this.zongjie = zongjie; } public String getInday() { return inday; } public void setInday(String inday) { this.inday = inday; } public String getMaxday() { return maxday; } public void setMaxday(String maxday) { this.maxday = maxday; }} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package com;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;public class Util { private String url="jdbc:mysql://localhost:3306/db-jsp"; private String user="root"; private String password="123456"; private String driver="com.mysql.jdbc.Driver"; public Connection getCon() throws Exception{ Class.forName(driver); Connection con=DriverManager.getConnection(url, user, password); return con; } public static void getClose(Connection con) throws SQLException{ if(con!=null){ con.close(); } }} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package com;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class web extends HttpServlet { Util db=new Util(); private static final long serialVersionUID = 1L; public PublishServlet() { super(); } public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); String riqi=request.getParameter("riqi"); String keyword=request.getParameter("keyword"); String zongjie=request.getParameter("zongjie"); String inday=request.getParameter("inday"); String maxday=request.getParameter("maxday"); Interface=new Interface(); Interface.setriqi(riqi); literature.setEnglishName(EnglishName); literature.setType(Type); literature.setAuthor(Author); literature.setSource(Source); literature.setChineseAbstract(ChineseAbstract); literature.setEnglishAbstract(EnglishAbstract); literature.setChineseKeyword(ChineseKeyword); literature.setEnglishKeyword(EnglishKeyword); literature.setReforName(ReforName); literature.setIncentive(Incentive); literature.setContent(Content); LiteratureInterface literatureInter=new LiteratureInterface(); literatureInter.addLiterature(literature); request.getRequestDispatcher("main.jsp").forward(request, response); } public void init() throws ServletException { // Put your code here }} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %><html> <head> <title>每日总结打卡</title> </head> <body> <form action="PublishServlet" method="post"> <table> <tr> <td>日期:</td> <td><input type="text" name="riqi" value="${param.riqi}"></td> </tr> <tr> <td>每日关键字:</td> <td><input type="text" name="keyword" value="${param.keyword}"></td> </tr> <tr> <td>每日总结:</td> <td><input type="text" name="zongjie" value="${param.zongjie}"></td> </tr> <tr> <td>坚持天数:</td> <td><input type="text" name="inday" value="${param.inday}"></td> </tr> <tr> <td>连续最长天数:</td> <td><input type="text" name="maxday" value="${param.maxday}"></td> </tr> </tr> <tr> <td> <input type="submit" value="提交"> </td> </tr> </table> </form> </body></html> |


浙公网安备 33010602011771号