获取debit-credit-sdate的余额时出错
<ul class="nav navbar-nav navbar-right navmenu">
<li data-menuanchor="home" class="active">
<a href="#home"><span>HOME</span></a>
</li>
<li data-menuanchor="page">
<a href="#page"><span>ABOUT US</span></a>
</li>
<li data-menuanchor="gallery">
<a href="#gallery"><span>PROJECTS</span></a>
</li>
<li data-menuanchor="aboutus">
<a href="#aboutus"><span>VIDEO</span></a>
</li>
<li data-menuanchor="contact" class="cont">
<a href="#contact"><span>CONTACT</span></a>
</li>
</ul>
数据库是AccID-用户名AccNo借方贷方余额sDate
如何像任何银行存折类型一样,为运行帐户数据库获取余额。
我正在尝试开发上面的代码JSP页面,但是每次运行时都没有发生错误,但数据库中没有数据响应,当我只更新帐户时,每个特定帐户[sdatewise类型的数量]正在更新
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%>
<%@ page import="java.util.Calendar" %>
<%
//java Code
String date = (new java.util.Date()).toString();
String UserName = request.getParameter("UserName");
String CusId= request.getParameter("CusId");
String AccountNo = request.getParameter("AccountNo");
String Debit = request.getParameter("Debit");
String Credit=request.getParameter("Credit");
String Balance=request.getParameter("Balance");
String sDate=request.getParameter("sDate");
try
{
String s="jdbc:odbc:Database1";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(s);
Statement smt=conn.createStatement();
Calendar calendar = Calendar.getInstance();
java.sql.Date startDate = new java.sql.Date(calendar.getTime().getTime());
String sql= "SELECT sDate, (SUM(Debit)*-1) + SUM(Credit)Balance FROM abcbank GROUP BY sDate";
ResultSet result = smt.executeQuery(sql);
int count = 0;
while (result.next())
{
result.getString(1,"Debit");
result.getString(2,"Credit");
result.getString(3,"Balance");
result.getDate(4,startDate);
}
String update= "UPDATE abcbank SET Balance =Debit + Balance WHERE AccountNo="+AccountNo+" ";
PreparedStatement statement = conn.prepareStatement(update);
//statement.setString(1,"AccountNo");
int rowsUpdated = statement.executeUpdate();
if (rowsUpdated ==0)
{
out.println("This Emp does not Exists!");
}
else if(rowsUpdated ==1)
{
out.println("An existing user was updated successfully!");
}
conn.close();
}
catch(Exception ex)
{
System.err.println(ex.getMessage());
}
%>
</body>
</html>
像这样。
答案 0 :(得分:0)
这里有一个明显的问题:(SUM(Debit)*-1) + SUM(Credit)Balance
。假设借方和贷方始终存在,则应为SUM(Credit)-SUM(Debit) AS Balance
,否则应为SUM(Nz(Credit,0))-SUM(Nz(Debit,0)) AS Balance
此外:
result.getString(1,"Debit");
result.getString(2,"Credit");
result.getString(3,"Balance");
result.getDate(4,startDate);
这似乎并没有真正做任何事情,但也许这就是它对我的看法,因为我不使用jsp。但是,
您的查询仅返回字段:sDate
和Balance
。将SELECT sDate,
更改为SELECT sDate AS startDate, SUM(Nz(Debit,0)) AS Debit, SUM(Nz(Credit,0)) AS Credit,
result.getDate(4,startDate);
也可能是result.getDate(4,"startDate");
这些只是最明显的问题;可能会有更多。