jsp怎么从mysql数据库把树形结构展现出来

jsp怎么从mysql数据库把树形结构展现出来,第1张

jsp从mysql数据库读取数据,并填充到树形结构菜单并展现出来的实现方法:

1、引入jquery.treeview.js树控件

<script type="text/javascript" src="jquery/easyui/jquery.min.js"></script>

 <script type="text/javascript" src="jquery/easyui/jquery.easyui.min.js"></script>

2、jsp页面中获取后台mysql数据,并传到jsp页面来

<% 

// 数据库的名字

String dbName = "zap"

// 登录数据库的用户名

String username = "sa"

// 登录数据库的密码

String password = "123"

// 数据库的IP地址,本机可以用 localhost 或者 127.0.0.1

String host = "127.0.0.1"

// 数据库的端口,一般不会修改,默认为1433

int port = 1433

String connectionUrl = "jdbc:sqlserver://" + host + ":" + port + "databaseName=" + dbName + "user=" + username

+ "password=" + password

//

//声明需要使用的资源 

// 数据库连接,记得用完了一定要关闭

Connection con = null

// Statement 记得用完了一定要关闭

Statement stmt = null

// 结果集,记得用完了一定要关闭

ResultSet rs = null

try {

// 注册驱动 

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")

// 获得一个数据库连接

con = DriverManager.getConnection(connectionUrl)

String SQL = "SELECT * from note"

// 创建查询

stmt = con.createStatement()

// 执行查询,拿到结果集

rs = stmt.executeQuery(SQL)

while (rs.next()) {

%>

<tr>

3、填充树形菜单:

{

 id          : "string" // will be autogenerated if omitted

 text        : "string" // node text

 icon        : "string" // string for custom

 state       : {

   opened    : boolean  // is the node open

   disabled  : boolean  // is the node disabled

   selected  : boolean  // is the node selected

 },

 children    : []  // array of strings or objects

 li_attr     : {}  // attributes for the generated LI node

 a_attr      : {}  // attributes for the generated A node

}

$('#tree').jstree({

   'core' : {

       'data' : function (obj, cb) {

           cb.call(this,

             ['Root 1', 'Root 2'])

       }

   }})

可以使用以下代码在EXCEL上使用VBA连接MYSQL数据库    :

Dim strconnt As String

  strconnt = ""

  Set connt = New ADODB.Connection

  Dim sevip, Db, user, pwd As String

  '设服务器地址、所连数据,及登录用户密码

  sevip = "localhost"

  Db = “test"

  user = "root"

  pwd = "123456"

  strconnt = "DRIVER={MySql ODBC 5.3 Unicode Driver}SERVER=" & sevip & "Database=" & Db & "Uid=" & user & "Pwd=" & pwd & "Stmt=set names GBK"

  connt.ConnectionString = strconnt

  connt.Open

//参考这个最基本的吧:

<?php

$link = mysql_connect('localhost', 'root', '123456')

mysql_select_db('youdatabase', $link)

$result = mysql_query('SELECT id, title FROM table', $link)

?>

<html>

    <head>

        <title>文章列表</title>

    </head>

    <body>

        <h1>文章列表</h1>

        <ul>

            <?php while ($row = mysql_fetch_assoc($result)): ?>

            <li>

                <a href="/show.php?id=<?php echo $row['id'] ?>">

                    <?php echo $row['title'] ?>

                </a>

            </li>

            <?php endwhile ?>

        </ul>

    </body>

</html>

 

<?php

mysql_close($link)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8500604.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-17
下一篇 2023-04-17

发表评论

登录后才能评论

评论列表(0条)

保存