最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > jsp教程

JSP实现MySQL数据结构查询

日期:10-15    来源:中国设计秀    作者:cnwebshow.com

流程简介:JAQ中国设计秀

                                 login                                use                    describeJAQ中国设计秀

                    登录<----------->选择数据库<--------->选择表<---------->显示表结构JAQ中国设计秀

                                logout                              back                      backJAQ中国设计秀

0.数据库处理的javabean:(我厚道吧,这都贴出来了)JAQ中国设计秀

MySQLmeans.java(位置:MySQL/mysqlmeans.java):JAQ中国设计秀

package MySQL;JAQ中国设计秀
import java.sql.*;JAQ中国设计秀
/**JAQ中国设计秀
 *JAQ中国设计秀
 * @author luciferJAQ中国设计秀
 */JAQ中国设计秀

public class mysqlmeans {JAQ中国设计秀
     Connection con;JAQ中国设计秀
    String username = "";JAQ中国设计秀
    String password = "";JAQ中国设计秀
     String server = "";JAQ中国设计秀
     String dbname = "";JAQ中国设计秀
     public void setPRoperties(String serv,String db,String name,String pass){JAQ中国设计秀
          server = serv;JAQ中国设计秀
          dbname = db;JAQ中国设计秀
          username = name;JAQ中国设计秀
          password = pass;JAQ中国设计秀
     }JAQ中国设计秀

     public void setUserName(String username){JAQ中国设计秀
          this.username = username;JAQ中国设计秀
     }JAQ中国设计秀
     public String getUserName(){JAQ中国设计秀
          return username;JAQ中国设计秀
     }JAQ中国设计秀

     public void setPassword(String password){JAQ中国设计秀
          this.password = password;JAQ中国设计秀
     }JAQ中国设计秀
     public String getPassword(){JAQ中国设计秀
          return password;JAQ中国设计秀
     }JAQ中国设计秀

     public void setServer(String server){JAQ中国设计秀
          this.server = server;JAQ中国设计秀
     }JAQ中国设计秀
     public String getServer(){JAQ中国设计秀
          return server;JAQ中国设计秀
     }JAQ中国设计秀

     public void setDataBase(String daname){JAQ中国设计秀
          this.dbname = daname;JAQ中国设计秀
     }JAQ中国设计秀
     public String getDataBase(){JAQ中国设计秀
          return dbname;JAQ中国设计秀
     }JAQ中国设计秀

     public Connection getConnection(){JAQ中国设计秀
        try{JAQ中国设计秀
            Class.forName("com.mysql.jdbc.Driver");JAQ中国设计秀
            con = DriverManager.getConnectionJAQ中国设计秀
                       ("jdbc:mysql://"+server+"/"+dbname+"?user="+username+"&password="+password, username, password);JAQ中国设计秀
            return con;JAQ中国设计秀
        }catch(Exception e){JAQ中国设计秀
            e.printStackTrace();JAQ中国设计秀
            return null;JAQ中国设计秀
        }JAQ中国设计秀
    }JAQ中国设计秀

    public void exeUpdate(String sql){JAQ中国设计秀
        Connection upCon = getConnection();JAQ中国设计秀
        try{JAQ中国设计秀
            Statement stmt = upCon.createStatement();JAQ中国设计秀
            stmt.executeUpdate(sql);JAQ中国设计秀
            stmt.close();JAQ中国设计秀
            upCon.close();JAQ中国设计秀
        }catch(Exception e){JAQ中国设计秀
            e.printStackTrace();JAQ中国设计秀
        }JAQ中国设计秀
    }JAQ中国设计秀

    public ResultSet getResult(String sql){JAQ中国设计秀
        ResultSet rs = null;JAQ中国设计秀
        try{JAQ中国设计秀
            Statement stmt = con.createStatementJAQ中国设计秀
                       (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);JAQ中国设计秀
            rs = stmt.executeQuery(sql);JAQ中国设计秀
        }catch(Exception e){JAQ中国设计秀
            e.printStackTrace();JAQ中国设计秀
        }JAQ中国设计秀
        return rs;JAQ中国设计秀
    }JAQ中国设计秀

    public void closeConnection(){JAQ中国设计秀
        try{JAQ中国设计秀
            con.close();JAQ中国设计秀
        }catch(Exception e){JAQ中国设计秀
            e.printStackTrace();JAQ中国设计秀
        }JAQ中国设计秀
    }JAQ中国设计秀

    public void closeResultSet(ResultSet rs){JAQ中国设计秀
        try{JAQ中国设计秀
            rs.close();JAQ中国设计秀
        }catch(Exception e){JAQ中国设计秀
            e.printStackTrace();JAQ中国设计秀
        }JAQ中国设计秀
    }JAQ中国设计秀

    public void closeStatement(Statement stmt){JAQ中国设计秀
        try{JAQ中国设计秀
            stmt.close();JAQ中国设计秀
        }catch(Exception e){JAQ中国设计秀
            e.printStackTrace();JAQ中国设计秀
        }JAQ中国设计秀
    }JAQ中国设计秀

}JAQ中国设计秀

 JAQ中国设计秀

JAQ中国设计秀
1.登录:JAQ中国设计秀

login.jsp:JAQ中国设计秀

<%--JAQ中国设计秀
    Document   : chooseJAQ中国设计秀
    Created on : 2009-10-5, 19:07:36JAQ中国设计秀
    Author     : luciferJAQ中国设计秀
--%>JAQ中国设计秀

<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="login_error.jsp"%>JAQ中国设计秀
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"JAQ中国设计秀
   "http://www.w3.org/TR/html4/loose.dtd">JAQ中国设计秀

<html>JAQ中国设计秀
    <head>JAQ中国设计秀
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">JAQ中国设计秀
        <title>登录</title>JAQ中国设计秀
    </head>JAQ中国设计秀
    <body bgcolor="#c0c0c0">JAQ中国设计秀
         <center>JAQ中国设计秀
              <font face="楷体" size="+3">JAQ中国设计秀
                   Sir_LuciFer<br>数据库查询系统JAQ中国设计秀
              </font>JAQ中国设计秀
              <br><br>JAQ中国设计秀
              <form method="post" action="chooseDataBase.jsp" name="form">JAQ中国设计秀
              <B>JAQ中国设计秀
              服务器:JAQ中国设计秀
              <input type="text" name="server" value="localhost"><br>JAQ中国设计秀
              用户名:JAQ中国设计秀
              <input type="text" name="username" value="root"><br>JAQ中国设计秀
              密码:JAQ中国设计秀
              <input type="password" name="password"><br>JAQ中国设计秀
              <input type="submit" value="Login!">JAQ中国设计秀
              </B>JAQ中国设计秀
         </form>JAQ中国设计秀
         </center>JAQ中国设计秀
    </body>JAQ中国设计秀
</html> JAQ中国设计秀
http://www.knowsky.com/JAQ中国设计秀

2.选择要使用的数据库:JAQ中国设计秀

chooseDataBase.jsp:JAQ中国设计秀

<%-- JAQ中国设计秀
    Document   : chooseJAQ中国设计秀
    Created on : 2009-10-5, 19:07:36JAQ中国设计秀
    Author     : luciferJAQ中国设计秀
--%>JAQ中国设计秀

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>JAQ中国设计秀
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"JAQ中国设计秀
   "http://www.w3.org/TR/html4/loose.dtd">JAQ中国设计秀
<jsp:useBean id="mysql" class="MySQL.mysqlmeans"/>JAQ中国设计秀
<html>JAQ中国设计秀
    <head>JAQ中国设计秀
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">JAQ中国设计秀
        <title>选择数据库</title>JAQ中国设计秀
        <script type="text/Javascript">JAQ中国设计秀
             function getDataBase(){JAQ中国设计秀
                  alert(document.getElementById("db").value)JAQ中国设计秀
             }JAQ中国设计秀
        </script>JAQ中国设计秀
    </head>JAQ中国设计秀
    <%JAQ中国设计秀
          String user = request.getParameter("username");JAQ中国设计秀
          String pass = request.getParameter("password");JAQ中国设计秀
          String serv = request.getParameter("server");JAQ中国设计秀
          mysql.setUserName(user);JAQ中国设计秀
          mysql.setPassword(pass);JAQ中国设计秀
          mysql.setServer(serv);JAQ中国设计秀
          String sql = "show databases";JAQ中国设计秀

          mysql.getConnection();JAQ中国设计秀
          ResultSet rs = mysql.getResult(sql);JAQ中国设计秀
    %>JAQ中国设计秀

    <body bgcolor="#c0c0c0">JAQ中国设计秀
         <center>JAQ中国设计秀
         <table border="1px">JAQ中国设计秀
              <tr>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        数据库:JAQ中国设计秀
                   </td>JAQ中国设计秀
              </tr>JAQ中国设计秀
              <%JAQ中国设计秀
                    while(rs.next()){%>JAQ中国设计秀
                    <tr>JAQ中国设计秀
                    <td>JAQ中国设计秀
                         <%=rs.getString("Database")%>JAQ中国设计秀
                    </td>JAQ中国设计秀
                         </tr>JAQ中国设计秀
                    <%JAQ中国设计秀
                    }JAQ中国设计秀
                    mysql.closeResultSet(rs);JAQ中国设计秀
                    mysql.closeConnection();JAQ中国设计秀
                %>JAQ中国设计秀
         </table>JAQ中国设计秀
         <form method="post" action="chooseTable.jsp" name="form">JAQ中国设计秀
              <B>JAQ中国设计秀
              请选择数据库名称:JAQ中国设计秀
              </B>JAQ中国设计秀
              <input type="text" name="database" value="test"><br>                         JAQ中国设计秀
              <input type="hidden" name="username" value="<%=user%>">JAQ中国设计秀
              <input type="hidden" name="password" value="<%=pass%>">JAQ中国设计秀
              <input type="hidden" name="server" value="<%=serv%>">JAQ中国设计秀
              <input type="submit" value="USE!">JAQ中国设计秀
         </form>JAQ中国设计秀
         <form method="post" action="login.jsp">JAQ中国设计秀
                   <input type="submit" value="Logout!">JAQ中国设计秀
         </form>JAQ中国设计秀
         </center>JAQ中国设计秀
    </body>JAQ中国设计秀
</html>JAQ中国设计秀

 JAQ中国设计秀

 JAQ中国设计秀

 JAQ中国设计秀

3.选择表并看其结构:JAQ中国设计秀

chooseTable.jsp:JAQ中国设计秀

<%-- JAQ中国设计秀
    Document   : chooseTableJAQ中国设计秀
    Created on : 2009-10-5, 19:19:37JAQ中国设计秀
    Author     : luciferJAQ中国设计秀
--%>JAQ中国设计秀

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>JAQ中国设计秀
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"JAQ中国设计秀
   "http://www.w3.org/TR/html4/loose.dtd">JAQ中国设计秀
<jsp:useBean id="mysql" class="MySQL.mysqlmeans"/>JAQ中国设计秀
<%JAQ中国设计秀
          String user = request.getParameter("username");JAQ中国设计秀
          String pass = request.getParameter("password");JAQ中国设计秀
          String serv = request.getParameter("server");JAQ中国设计秀
          String dbname = request.getParameter("database");JAQ中国设计秀
          mysql.setUserName(user);JAQ中国设计秀
          mysql.setPassword(pass);JAQ中国设计秀
          mysql.setServer(serv);JAQ中国设计秀
          mysql.setDataBase(dbname);JAQ中国设计秀
          String sql = "show tables";JAQ中国设计秀

          mysql.getConnection();JAQ中国设计秀
          ResultSet rs = mysql.getResult(sql);JAQ中国设计秀

%>JAQ中国设计秀
<html>JAQ中国设计秀
    <head>JAQ中国设计秀
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">JAQ中国设计秀
        <title>选择表</title>JAQ中国设计秀
    </head>JAQ中国设计秀
    <body bgcolor="#c0c0c0">JAQ中国设计秀
         <center>JAQ中国设计秀
         <table border="1px">JAQ中国设计秀
              <tr>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        表:JAQ中国设计秀
                   </td>JAQ中国设计秀
              </tr>JAQ中国设计秀
              <%JAQ中国设计秀
                    while(rs.next()){%>JAQ中国设计秀
                    <tr>JAQ中国设计秀
                    <td>JAQ中国设计秀
                         <%=rs.getString("Tables_in_" + dbname)%>JAQ中国设计秀
                    </td>JAQ中国设计秀
                         </tr>JAQ中国设计秀
                    <%JAQ中国设计秀
                    }JAQ中国设计秀
                %>JAQ中国设计秀
         </table>JAQ中国设计秀
         <form method="post" action="describeTable.jsp" name="form2">JAQ中国设计秀
              <B>请选择一个表:JAQ中国设计秀
              <input type="text" name="table">JAQ中国设计秀
              <input type="hidden" name="username" value="<%=user%>">JAQ中国设计秀
              <input type="hidden" name="password" value="<%=pass%>">JAQ中国设计秀
              <input type="hidden" name="server" value="<%=serv%>">JAQ中国设计秀
              <input type="hidden" name="database" value="<%=dbname%>">JAQ中国设计秀
              <br>JAQ中国设计秀
              <input type="submit" value="DESCRIBE!">JAQ中国设计秀
              </B>JAQ中国设计秀
         </form>JAQ中国设计秀

JAQ中国设计秀
         <form method="post" action="chooseDataBase.jsp" name="form1">JAQ中国设计秀
              <B>JAQ中国设计秀
              <input type="hidden" name="username" value="<%=user%>">JAQ中国设计秀
              <input type="hidden" name="password" value="<%=pass%>">JAQ中国设计秀
              <input type="hidden" name="server" value="<%=serv%>">JAQ中国设计秀
              <input type="submit" value="BACK!">JAQ中国设计秀
              </B>JAQ中国设计秀
         </form>JAQ中国设计秀
         </center>JAQ中国设计秀
    </body>JAQ中国设计秀
</html>JAQ中国设计秀

 JAQ中国设计秀

JAQ中国设计秀
4.描述表:JAQ中国设计秀

describeTable.jsp:JAQ中国设计秀

<%-- JAQ中国设计秀
    Document   : describeTableJAQ中国设计秀
    Created on : 2009-10-6, 19:49:26JAQ中国设计秀
    Author     : luciferJAQ中国设计秀
--%>JAQ中国设计秀

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>JAQ中国设计秀
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"JAQ中国设计秀
   "http://www.w3.org/TR/html4/loose.dtd">JAQ中国设计秀
<jsp:useBean id="mysql" class="MySQL.mysqlmeans"/>JAQ中国设计秀
<html>JAQ中国设计秀
    <head>JAQ中国设计秀
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">JAQ中国设计秀
        <title>Describe table <%=request.getParameter("table")%></title>JAQ中国设计秀
    </head>JAQ中国设计秀
    <%JAQ中国设计秀
    String serv = request.getParameter("server");JAQ中国设计秀
    String user = request.getParameter("username");JAQ中国设计秀
    String pass = request.getParameter("password");JAQ中国设计秀
    String dbname = request.getParameter("database");JAQ中国设计秀
    String tname = request.getParameter("table");JAQ中国设计秀
    mysql.setServer(serv);JAQ中国设计秀
    mysql.setUserName(user);JAQ中国设计秀
    mysql.setPassword(pass);JAQ中国设计秀
    mysql.setDataBase(dbname);JAQ中国设计秀
    String sql = "describe " + tname;JAQ中国设计秀
    JAQ中国设计秀
    mysql.getConnection();JAQ中国设计秀
    ResultSet rs = mysql.getResult(sql);JAQ中国设计秀

    %>JAQ中国设计秀
    <body bgcolor="#c0c0c0">JAQ中国设计秀
         <center>JAQ中国设计秀
         <table border="1px">JAQ中国设计秀
              <tr>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        FieldJAQ中国设计秀
                   </td>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        TypeJAQ中国设计秀
                   </td>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        NullJAQ中国设计秀
                   </td>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        KeyJAQ中国设计秀
                   </td>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        DefaultJAQ中国设计秀
                   </td>JAQ中国设计秀
                   <td>JAQ中国设计秀
                        ExtraJAQ中国设计秀
                   </td>JAQ中国设计秀
              </tr>JAQ中国设计秀
              <%JAQ中国设计秀
                    while(rs.next()){JAQ中国设计秀
                   %>JAQ中国设计秀
                         <tr>JAQ中国设计秀
                              <td>JAQ中国设计秀
                                   <%=rs.getString("Field")%>JAQ中国设计秀
                              </td>JAQ中国设计秀
                              <td>JAQ中国设计秀
                                   <%=rs.getString("Type")%>JAQ中国设计秀
                              </td>JAQ中国设计秀
                              <td>JAQ中国设计秀
                                   <%=rs.getString("Null")%>JAQ中国设计秀
                              </td>JAQ中国设计秀
                              <td>JAQ中国设计秀
                                   <%=rs.getString("Key")%>JAQ中国设计秀
                              </td>JAQ中国设计秀
                              <td>JAQ中国设计秀
                                   <%=rs.getString("Default")%>JAQ中国设计秀
                              </td>JAQ中国设计秀
                              <td>JAQ中国设计秀
                                   <%=rs.getString("Extra")%>JAQ中国设计秀
                              </td>JAQ中国设计秀
                         </tr>JAQ中国设计秀
             <%JAQ中国设计秀
                    }JAQ中国设计秀
              %>JAQ中国设计秀
         </table>JAQ中国设计秀
         <form method="post" action="chooseTable.jsp">JAQ中国设计秀
              <input type="hidden" name="username" value="<%=user%>">JAQ中国设计秀
              <input type="hidden" name="password" value="<%=pass%>">JAQ中国设计秀
              <input type="hidden" name="server" value="<%=serv%>">JAQ中国设计秀
              <input type="hidden" name="database" value="<%=dbname%>">JAQ中国设计秀
              <input type="submit" value="BACK!">JAQ中国设计秀
         </form>JAQ中国设计秀
         </center>JAQ中国设计秀
    </body>JAQ中国设计秀
</html>JAQ中国设计秀

本文引用地址:/bc/article_46559.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明