gpt4 book ai didi

java - 用java更新mysql

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:46 24 4
gpt4 key购买 nike

我的数据库包含 2 列用户名和余额。 username 的值为 Mike,balance 的值为 null。我正在尝试更新余额,但由于某种原因它没有更新。我也没有收到任何错误。有什么建议

 <p>This is the deposit page</p>
<form action="deposit.jsp" method="POST">
<label>deposit: </label><input type="text" name="deposit"><br>
<label>name: </label><input type="text" name="name"><br>
<input type="submit" value="deposit">

<%

String deposit=request.getParameter("deposit");
String name=request.getParameter("name");
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=null;
st=conn.createStatement();
st.executeUpdate("update username set balance='"+deposit+"' where username='"+name+"'");

}
catch(Exception e){
System.out.println(e);
}
%>
</form>
</body>
</html>

最佳答案

添加:conn.commit()
在 block 的末尾

关于java - 用java更新mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10626146/

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