gpt4 book ai didi

mysql - 使用 JSP 和 MySQL 执行查询时自动插入空值

转载 作者:可可西里 更新时间:2023-11-01 08:34:17 25 4
gpt4 key购买 nike

当我执行下面的代码时,在每次插入之前,自动用 Null 值填充一行,然后插入实际值。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Connecting to a Data base</title>
</head>
<body>

<%
String connectionURL="jdbc:mysql://localhost:3306/jsp_test";
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "exeterblr");
if(!connection.isClosed()) {
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
}
else
{
out.println("Cannot connect to DB");
}
String name=request.getParameter("name");
String email=request.getParameter("email");
String phone=request.getParameter("phone");
PreparedStatement pstatement=null;
int updateTable=0;
String queryString = "INSERT INTO sample_info(name,email,phone) VALUES (?, ?, ?)";
pstatement=connection.prepareStatement(queryString);
pstatement.setString(1, name);
pstatement.setString(2, email);
pstatement.setString(3, phone);

updateTable=pstatement.executeUpdate();
%>



<form method="post" action="index.jsp">
<table>
<tr>
<td>Name</td><td><input type="text" name="name"></td>
</tr>
<tr>
<td>Email</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td>Phone</td><td> <input type="text" name="phone"></td>
</tr>

</table>
<input type="submit" value="Submit">
</form>


</body>

当我插入一个值时,数据库包含以下内容:

Name Email Phone <br />
NULL NULL NULL <br />
ActualValue ActualValue Actual Value

最佳答案

您每次访问网页时都插入 (NULL,NULL,NULL),而不仅仅是在提交时。

关于mysql - 使用 JSP 和 MySQL 执行查询时自动插入空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17782357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com