| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| |
| = NetBeans 电子商务教程 - 设置指导 |
| :jbake-type: tutorial |
| :jbake-tags: tutorials |
| :jbake-status: published |
| :icons: font |
| :syntax: true |
| :source-highlighter: pygments |
| :toc: left |
| :toc-title: |
| :description: NetBeans 电子商务教程 - 设置指导 - Apache NetBeans |
| :keywords: Apache NetBeans, Tutorials, NetBeans 电子商务教程 - 设置指导 |
| |
| |
| |
| 1. link:intro.html[+简介+] |
| 2. link:design.html[+设计应用程序+] |
| 3. link:setup-dev-environ.html[+设置开发环境+] |
| 4. link:data-model.html[+设计数据模型+] |
| 5. link:page-views-controller.html[+准备页面视图和控制器 Servlet+] |
| 6. link:connect-db.html[+将应用程序与数据库连接+] |
| 7. link:entity-session.html[+添加实体类和会话 Bean+] |
| 8. link:manage-sessions.html[+管理会话+] |
| 9. link:transaction.html[+集成事务性业务逻辑+] |
| 10. link:language.html[+添加语言支持+] |
| 11. link:security.html[+保护应用程序+] |
| 12. link:test-profile.html[+测试和性能分析+] |
| 13. link:conclusion.html[+小结+] |
| |
| image::../../../../images_www/articles/68/netbeans-stamp-68-69.png[title="此页上的内容适用于 NetBeans IDE 版本 6.8 和 6.9"] |
| |
| 如果要在未完成前一教程单元的情况下继续学习下一单元,则需要执行一些预备步骤,以设置开发环境。 |
| |
| 1. *设置 MySQL 数据库服务器*。按照link:setup-dev-environ.html#communicate[+与数据库服务器进行通信+]中所述的步骤操作。 |
| 2. *在数据库服务器上创建 `affablebean` 方案,并使用样例数据填充数据库:* |
| .. 单击 link:https://netbeans.org/projects/samples/downloads/download/Samples%252FJavaEE%252Fecommerce%252Faffablebean.sql[+affablebean.sql+] 并复制(Ctrl-C;在 Mac 上为 ⌘-C)文件的所有内容。 |
| .. 打开 IDE 的 SQL 编辑器。在 "Services"(服务)窗口(按 Ctrl-5 组合键;在 Mac 上为 ⌘-5 组合键)中,右键单击 `affablebean` 数据库连接 (image:images/db-connection-node.png[]) 节点,然后选择 "Execute Command"(执行命令)。 |
| |
| image::images/execute-command.png[title="从连接节点中选择 "] |
| |
| IDE 的 SQL 编辑器打开。 |
| |
| [start=3] |
| . 将 `affablebean.sql` 文件的所有内容粘贴(Ctrl-V;在 Mac 上为 ⌘-V)至编辑器。 |
| |
| [start=4] |
| . 在编辑器的工具栏中单击 "Run SQL"(运行 SQL)(image:images/run-sql-btn.png[]) 按钮。此脚本在 MySQL 服务器上运行。为数据库生成表,并将样例数据添加到 `product` 和 `category` 表。 |
| |
| [start=3] |
| . *在 GlassFish 上创建连接池和 JDBC 源。* |
| 1. 在 "Services"(服务)窗口(Ctrl-5 组合键;在 Mac 上为 ⌘-5 组合键)中,展开 "Servers"(服务器)> "GlassFish Server 3" 节点,并选择 "Properties"(属性)。在显示的 "Servers"(服务器)窗口中,请确保选中 "Enable JDBC Driver Deployment"(启用 JDBC 驱动程序部署)。如果项目需要 MySQL link:http://www.mysql.com/downloads/connector/j/[+Connector/J+] 驱动程序,则此选项会确保在部署项目时将驱动程序部署到 GlassFish 上。(如果服务器已在运行,则需要重新启动服务器。) |
| 2. 在 "Services"(服务)窗口中,右键单击 "GlassFish Server 3" 节点并选择 "Start"(启动)。 |
| 3. 运行该服务器之后,右键单击 "GlassFish Server 3" 节点,然后选择 "View Admin Console"(查看管理控制台)。 |
| 4. 登录到(默认用户名/口令为:`admin/adminadmin`)。 |
| 5. 在管理控制台左侧的树中,展开 "Resources"(资源)> "JDBC" 节点,然后单击 "Connection Pools"(连接池)节点。 |
| 6. 在 "Connection Pools"(连接池)接口中,单击 "New"(新建)按钮,并输出以下详细信息: |
| * *Name(名称):*`AffableBeanPool` |
| * *Resource Type(资源类型):*`javax.sql.ConnectionPoolDataSource` |
| * *Database Vendor(数据库供应商):*`MySql` |
| |
| image::images/connection-pool.png[title="指定设置以创建连接至 MySQL 数据库的连接池"] |
| |
| [start=7] |
| . 单击 "Next"(下一步)。接受所有默认值,然后单击 "Finish"(完成)。 |
| |
| [start=8] |
| . 在 "Connection Pools"(连接池)接口中,单击新创建的 `AffableBeanConnectionPool`,在 "General"(常规)标签下进行以下更改: |
| * *Datasource Classname(数据源类名):*`com.mysql.jdbc.jdbc2.optional.MysqlDataSource` |
| |
| image::images/datasource-classname.png[title="为连接池设置数据源类名"] |
| |
| [start=9] |
| . 单击 "Save"(保存)。 |
| |
| [start=10] |
| . 单击 "Additional Properties"(附加属性)标签,并确保已设置以下三个属性。(可能还列出其他属性,这些是默认设置,但是以下三个设置必须进行手动设置。) |
| * *User(用户):*`root` |
| * *Password(口令):*`nbuser` |
| * *URL:*`jdbc:mysql://localhost:3306/affablebean` |
| |
| image::images/additional-properties.png[title="设置用户名、口令和指向数据库的 URL"] |
| |
| [start=11] |
| . 单击 "Save"(保存)。 |
| |
| [start=12] |
| . 单击 "General"(常规)标签,然后单击 "Ping"。应会看到一则指示 ping 已成功的消息。`AffableBeanPool` 连接池现在可以连接到 MySQL 数据库服务器。 |
| |
| image::images/ping-succeeded.png[title="对 MySQL 服务器执行 ping 操作以确定连接池能否连接"] |
| |
| [start=13] |
| . 在左侧列中的管理控制台树中,单击 "Resources"(资源)> "JDBC" > "JDBC Resources"(JDBC 资源)节点。在主窗口中打开 "JDBC Resources"(JDBC 资源)界面。 |
| |
| [start=14] |
| . 单击 "New"(新建)按钮以创建新的 JDBC 资源,然后输入以下详细信息: |
| * *JNDI Name(JNDI 名称):*`jdbc/affablebean` |
| * *Connection Pool(连接池):*`AffableBeanPool` |
| |
| image::images/jdbc-resource.png[title="指定 JNDI 名称和连接池以创建 JDBC 资源"] |
| |
| [start=15] |
| . 单击 "OK"(确定)。 |
| |
| 已经设置 MySQL 服务器,并且可以从 IDE 的 "Services"(服务)窗口连接到此服务器。创建了名为 `affablebean` 的数据库,并使用样例数据填充了数据库的 `product` 和 `category` 表。然后,启动了 GlassFish Server,并创建一个连接池,服务器可通过它连接到 `affablebean` 数据库。最后,创建了一个 JDBC 资源,应用程序可使用它来引用服务器连接池的。 |
| |
| 现在,可以打开并运行教程单元中提供的任何项目屏幕快照。 |
| |
| link:/about/contact_form.html?to=3&subject=Feedback: NetBeans E-commerce Tutorial - Setup Instructions[+请将您的反馈意见发送给我们+] |
| |
| |