码迷,mamicode.com
首页 > 其他好文 > 详细

每日日报2021.1.29

时间:2021-06-20 17:55:34      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:private   root   print   show   for   import   cat   lse   cep   

今天完成内容:

开发家庭小账本

1.编写代码

package com.edu.entity;

import java.util.Date;

public class User {
private int id;
private String username;
private String userused;
private String usermoney;
private Date usedate;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserused() {
return userused;
}
public void setUserused(String userused) {
this.userused = userused;
}
public String getUsermoney() {
return usermoney;
}
public void setUsermoney(String usermoney) {
this.usermoney = usermoney;
}
public Date getUsedate() {
return usedate;
}
public void setUsedate(Date usedate) {
this.usedate = usedate;
}
public User(int id, String username, String userused, String usermoney, Date usedate) {
super();
this.id = id;
this.username = username;
this.userused = userused;
this.usermoney = usermoney;
this.usedate = usedate;
}
public User() {
}

}

 

package com.edu.entity;

import java.sql.Connection;

import java.sql.DriverManager;

 

public class DbHelper {

private static String url = "jdbc:mysql://localhost:3306/countuser"; // 数据库地址

private static String userName = "root"; // 数据库用户名

private static String passWord = "*****"; // 数据库密码

private static Connection conn = null;

 

private DbHelper() {

 

}

 

public static Connection getConnection() {

if (null == conn) {

try {

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection(url, userName, passWord);

} catch (Exception e) {

e.printStackTrace();

}

}

return conn;

}

 

public static void main(String[] args) { // 测试数据库是否连通

System.err.println(getConnection());

}

}

 

package com.edu.servlet;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.dao.Userdao;
import com.edu.entity.User;

@WebServlet("/Addservlet")
public class Addservlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
/*String ids = request.getParameter("id");
int id = Integer.parseInt(ids);*/
String username = request.getParameter("username");
String userused = request.getParameter("userused");
String usermoney = request.getParameter("usermoney");
String usedate = request.getParameter("usedate");
Date date = null;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(usedate);
} catch (ParseException e) {
// TODO 自动生成的 catc
e.printStackTrace();
}
User user = new User();
user.setUsername(username);
user.setUserused(userused);
user.setUsermoney(usermoney);
user.setUsedate(date);
Userdao dao = new Userdao();
if(dao.Addused(user))
{
System.out.println("添加成功!!");
}else
{
System.out.println("添加失败!!");
}
request.getRequestDispatcher("/Showall.jsp").forward(request,response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}

遇到问题:

增加数据失败

明日目标:

学习Android studio的开发

每日日报2021.1.29

标签:private   root   print   show   for   import   cat   lse   cep   

原文地址:https://www.cnblogs.com/leiyu1905/p/14905616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!