我是 Spring 框架和 java 的新手。我正在为我的网络应用程序创建注册模块。我创建了 DAO、DTO、Dispatcher Servlet、控制器等等。当我提交表单时,它会将我重定向到我想去的地方,但没有数据添加到数据库中。我的用户DTO.java package com.lagan.dto;public class userDto{ public String userId; public String firstName; public String lastName; public String birthDate; public int gender; public String email; public String password; public String getUserId() { return userId; } public String getUserId(String userId) { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getBirthDate() { return birthDate; } public void setBirthDate(String birthDate) { this.birthDate = birthDate; } public int getGender() { return gender; } public void setGender(int gender) { this.gender = gender; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password){ this.password = password; }}userDao.javapackage com.lagan.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.ArrayList;import java.util.List;import com.lagan.dbconnector.dbconnect;import com.lagan.dto.userDto;
2 回答
湖上湖
TA贡献2003条经验 获得超2个赞
我建议你这样连接
String url = "jdbc:mysql://localhost:3306/project_lagan";
String user = "root";
String password = "";
Connection conn = null;
try(conn = DriverManager.getConnection(url, user, password);) {
// processing here
} catch(SQLException e) {
System.out.println(e.getMessage());
}
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
尝试将连接字符串的端口号更改为以下之一:
`jdbc:mysql://localhost:3306/project_lagan`
或者
`jdbc:mysql://localhost/project_lagan`
添加回答
举报
0/150
提交
取消