日期:2014-05-18  浏览次数:20705 次

想把表中的数据显示出来
想把表中的数据显示出来.
package   gonggao;
import   java.sql.*;

public   class   Ggmain   {
private   String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydata;user=sa;password=520 ";
public   Ggmain(){
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}
catch   (Exception   ex){
ex.printStackTrace();
}

}


}
---------------------------------------
JSP文件调用BEAN
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<jsp:useBean   id= "Ggmain "   class= "gonggao.Ggmain "   scope= "page "> </jsp:useBean>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
<link   href= "css/textbox.css "   rel= "stylesheet "   type= "text/css ">
</head>

<body>
<%
Connection   con=null;
PreparedStatement   Ggps=null;
ResultSet   Ggrs=null;
String   sqlGg= "select   *   from   Ggaotabelme ";
con=DriverManager.getConnection(url);
Ggps=con.prepareStatement(sqlGg);
Ggrs=Ggps.executeQuery();
if(Ggrs.next()){

%>
<table   width= "100% "   border= "0 "   cellspacing= "0 "   cellpadding= "0 ">
    <tr>
        <td> <p> &nbsp; </p>

        <table   width= "50% "     border= "0 "   align= "center "   cellpadding= "0 "   cellspacing= "0 ">
            <tr>
                <td> <form   name= "form1 "   method= "post "   action= " ">
                    <div   align= "center "> 公告内容 <br>
                        <br>
                        <textarea   name= "textfield "   cols= "60 "   rows= "20 "   class= "textbox "> <%=Ggrs.getString( "G_res ")%> </textarea>
                    </div>
                </form> </td>
                </tr>
        </table>        
        <p   align= "center "> &nbsp; </p> </td>
    </tr>
</table>
<%}
Ggrs.close();
Ggps.close();
con.close();
%>
</body>
</html>
----------------------------
con=DriverManager.getConnection(url