着急 高手看看 JS结合JvavaScriopt查询数据并且用表格显示出来
<%@page language= "java " contentType= "text/html;charset=gb2312 "%>
<!--告诉编译器使用SQL包-->
<%@ page import= "java.util.* "%>
<%@ page import= "java.sql.* "%>
<html>
<head> <title> jsp实例 </title>
<%
String col2= " ";
String shtml= " ";
String sSQL= " ";
String fullsrc= " ";
String src = "http://127.0.0.1:9009?id= ";
try
{
Connection con;
Statement stmt;
ResultSet rs;
//加载驱动程序,下面的代码为加载JDBD-ODBC驱动程序
Class.forName( "oracle.jdbc.driver.OracleDriver ").newInstance();
//用适当的驱动程序连接到数据库,test "是系统dsn名
String url= "jdbc:oracle:thin:@192.168.1.110:1521:ora9i ";
String User = "gaczdata0004 ";
String PWD = "gold ";
//建立连接,类似于ASP中的创建数据库联接
con=DriverManager.getConnection(url, User, PWD);
//创建一个JDBC声明
stmt = con.createStatement();
//增加新记录
//stmt.executeUpdate( "INSERT INTO test (a,b) VALUES (1, "2 ") ");
//查询记录
sSQL = "select co.COMPANY_NAME,ca.ASSET_CARD_NO,ca.ASSET_CARD_NAME,da.DEPARTMENT_NAME,pe.FIRST_NAME || pe.LAST_NAME as ";
sSQL = sSQL + " Name,us.USER_NAME FROM COMPANY co,ZC_ASSET_CARD ca,DEPARTMENT da,PERSON pe,USER_LOGIN us where ";
sSQL = sSQL + "co.COMPANY_PARTY_ID = ca.COMPANY_PARTY_ID and da.DEPARTMENT_PARTY_ID = ca.DEPARTMENT_ID and ";
sSQL = sSQL + "pe.PARTY_ID=ca.EMPLOYEE_ID and us.USER_LOGIN_ID = ca.FH_USER_LOGIN_ID and ca.FH_USER_LOGIN_ID <> 'null ' ";
//sSQL = "select co.COMPANY_NAME,ca.ASSET_CARD_NO from COMPANY co,ZC_ASSET_CARD ca ";
rs = stmt.executeQuery(sSQL);
//sSQL = "select co.COMPANY_NAME,ca.ASSET_CARD_NO,ca.ASSET_CARD_NAME,da.DEPARTMENT_NAME,pe.FIRST_NAME || pe.LAST_NAME as ";
//sSQL = sSQL + " Name,us.USER_NAME FROM COMPANY co,ZC_ASSET_CARD ca,DEPARTMENT da,PERSON pe,USER_LOGIN us ";
rs = stmt.executeQuery(sSQL);
//输出查询结果
shtml = " <div style=\ "height:16px; width:80%; color:white;background-color:blue;\ "> ";
shtml += " <table width= '80% '> <tr> <td> <font style=\ "font-size:14px;color:white; width:30%; align:left;\ "> ";
shtml += "查询结果 </font> </td> <td> ";
shtml += " <a href= 'http://127.0.0.1:9090/QueryDataRight1.html '> <font style=\ "font-size:14px; color:white; ";
shtml += "width:70%;align:right;\ "> 返回 ";
shtml += " </font> </a> </td> </tr> </table> </div> ";
shtml += " <div> <table width= '80% ' style=\ "border:1 ;cellpadding=0 ;cellspacing=1 ;bgcolor== 'black '\ "> ";
shtml += " <tr bgcolor= '#f4f4f4 '> <td style=\ "width:%25; bgcolor= '#FFFFFF ' ;align=center; color: blue;\ "> 使用单位 </td> ";
shtml += " <td style=\ "width:15%;bgcolor= '#FFFFFF ';align=center; color: blue;\ "> 资产编号 </td> ";
shtml += " <td style=\ "width:23%; bgcolor= '#FFFFFF ' ;align=center; color: blue;\ "> 资产名称 </td> <td style=\ "width:15%; ";
shtml += "bgcolor= '#FFFFFF ' ;align=center; color: blue;\ "> 使用部门 </td> ";
shtml += " <td style=\ "width:11%; bgcolor= '#FFFFFF ' ;align=center; color: blue;\ "> 使用职员 </td> ";
shtml += " <td style=\ "width:11%; bgcolor= '#FFFFFF ' ;align=center; color: blue;\ "> 复核状态 </td> </tr> ";
while(rs.next()){
fullsrc = src +rs.getString( "COMPANY_NAME ");
shtml += " <tr> ";
shtml += " <td style=\ "align=center; color: black;\ "> "+ " <a href= ' "+fullsrc+ " '> "+rs.getString( "COMPANY_NAME ")+ " </a> </td> ";
shtml += " <td style=\ "align=center; color: black;\ "> "+rs.getString( "ASSET_CARD_NO ")+ " </td> ";
shtml += " <td style=\ "align=center; color: black;\ "> "+rs.getString( "ASSET_CARD_NAME ")+ " </td> ";
shtml += " <td style=\ "align=center; color: black;\ "> " + rs.getString( "DEPARTMENT_NAME ")+ " </td> ";
shtml += " <td style=\ "align=center; color: black;\ "> "+rs.getString( "Name ")+ " </td> ";
shtml += " <td style=\ "align=center; color: black;\ "> "+rs.getString( "USER_NAME ")+ " </td> "+ " </tr> ";
//rs.moveNext;
}
shtml += " </table> ";
//out.println( " <table border=1 width=400> ");
//for(int i=0;i < 5;i++)
//while (rs.next())
//{
//col2 = rs.getString( "COMPANY_NAME ");
//rs.next();
//String col1 = rs( "COMPANY_NAME ");
//String col2 = rs( "ASSET_CARD_NO ");
//out.println( " <tr> <td> "+col2+ " </td> </tr> ");
//}
//out.println( " </table> ");
}
//如果加载时出错,给出相应的错误信息
catch (Exception e) {}
finally{}
//String s= "你好! ";
%>
<script language= "javascript ">
//var testString= "hello! ";
document.write( " <%=shtml%> ");
</script>
</head>
<body>
</body>
</html>
[解决办法]
啥意思
[解决办法]
没明白你想问什么?
[解决办法]
希望你规范写法,这样太乱,自己查起来都费劲。。。