把复杂的查询SQL写在JSP中科以实现吗?
比如:%
String no[]=new String[500];
String weis[]=new String[500];
String shuie[]=new String[500];
Connection conn=null;
Statement Stmt=null;
ResultSet rs=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@194.1.1.236:1521:css";
String user="stdba";
String password="glq73hzz";
conn=DriverManager.getConnection(url,user,password);
Stmt=conn.createStatement();
String strquery=" select distinct a.section_no ||'-'||b.name as section ,
round(nvl(a.sales_amnt,0),4) as sales_amnt,
round(nvl(a.SALES_AMNT_VAT,0),2) as sales_amnt_vat,
(round(nvl(a.sales_amnt,0),2)+round(nvl(a.SALES_AMNT_VAT,0),2)) as sales_amnt_all,
(round(nvl(a.prom_sales_amnt,0),2)-round(nvl(a.c_sales_amnt,0),2)) as prom_sales_amnt,
round(nvl(a.prom_sales_amnt_vat,0),2)-round(nvl(a.c_sales_amnt_vat,0),2) as prom_sales_amnt_vat
from from section_stat_sales a";
try{
rs=Stmt.executeQuery(strquery);
}
catch(Exception e)
{
System.out.print(e+"数据库连接失败!");
}
在下面用表格输出数据
我怎么修改也不行
高手们指点一下
是 不是 复杂的查询不可以这样写
那复杂的计算用SQL怎么写在JSP中呢
比如:%
String no[]=new String[500];
String weis[]=new String[500];
String shuie[]=new String[500];
Connection conn=null;
Statement Stmt=null;
ResultSet rs=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@194.1.1.236:1521:css";
String user="stdba";
String password="glq73hzz";
conn=DriverManager.getConnection(url,user,password);
Stmt=conn.createStatement();
String strquery=" select distinct a.section_no ||'-'||b.name as section ,
round(nvl(a.sales_amnt,0),4) as sales_amnt,
round(nvl(a.SALES_AMNT_VAT,0),2) as sales_amnt_vat,
(round(nvl(a.sales_amnt,0),2)+round(nvl(a.SALES_AMNT_VAT,0),2)) as sales_amnt_all,
(round(nvl(a.prom_sales_amnt,0),2)-round(nvl(a.c_sales_amnt,0),2)) as prom_sales_amnt,
round(nvl(a.prom_sales_amnt_vat,0),2)-round(nvl(a.c_sales_amnt_vat,0),2) as prom_sales_amnt_vat
from from section_stat_sales a";
try{
rs=Stmt.executeQuery(strquery);
}
catch(Exception e)
{
System.out.print(e+"数据库连接失败!");
}
在下面用表格输出数据
我怎么修改也不行
高手们指点一下
是 不是 复杂的查询不可以这样写
那复杂的计算用SQL怎么写在JSP中呢
1:不建议把code和页面混在一起,日后维护困难,建议你采用MVC将页面和代码剥离。具体做法:
构造一个bean:DataBaseDao负责数据库查询更新等操作。
构造另外一个业务逻辑bean:实现计算功能。
2:在你的code中打开了连接,但最后没有关闭连接。
3:不建议在JSP中直接用JDBC访问数据库,可以考虑连接池等技术。
4:如果你的SQL在命令行窗口运行没问题,那么在jsp中也没问题。
很有可能是sql本身有问题。如果sql没错,请把错误帖出来