2.21学习体会

今天学习了“添加”的内容:

package dailysummer;

import java.sql.DriverManager;
import java.sql.Connection;

public class Main {

public String title;
public String content;
public String keyword;
public String time;



public void write(String title,String content,String keyword,String time) throws Exception {
String sql = "INSERT into daily VALUES('"+title+"','"+content+"','"+keyword+"','"+time+"')";


Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/abc";
String username = "root";
String Password = "123123";

Connection connection = DriverManager.getConnection(url, username, Password);
java.sql.Statement stmt = connection.createStatement();

stmt.executeUpdate(sql);
stmt.close();
}
}

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>每日总结</title>
</head>
<form action = "write.1.jsp" method = "get">
<div style = "text-align:center"><h2>每日总结</h2></div>
<br>
<table border = "0" style = "border-collapse:collapse" align="center">

<tr><td><font color="red">*</font>
总结标题<input type = "text" name = "title" size = "20" maxlength = "10">
</td></tr>

<tr><td><font color="red">*</font>
总结内容<input type = "text" name = "content" size = "20" maxlength = "10">
</td></tr>

<tr><td><font color="red">*</font>
关键字<input type = "text" name = "keyword" size = "20" maxlength = "10">
</td></tr>

<tr><td><font color="red">*</font>
总结日期<input type = "text" name = "time" size = "20" maxlength = "10">
</td></tr>

</table>

<div style = "text-align:center">
<br><input type = "submit" value = "提交">
</div>
</form>
</html>

能够较为熟练地链接数据库和画页面,但对调用函数还有欠缺。

posted @ 2023-02-21 22:12  听着DJ读童话  阅读(17)  评论(0)    收藏  举报