设为首页 收藏本站
查看: 1342|回复: 0

[经验分享] 看IBM网站的一个例子(2)

[复制链接]

尚未签到

发表于 2015-10-4 07:14:58 | 显示全部楼层 |阅读模式
  好,现在来建立到DB2的数据库连接,我机器上没装,随便抓几个图过过瘾好了,大概就是建立JDBC连接啦:
DSC0000.jpg

感觉其中的过滤器还是很强大地:可以设置取什么模式什么表或者不取满足什么条件的数据等等。
DSC0001.jpg



(连接名:BookData (随便起一个名字,自己知道就行了)
数据库:bookshop
用户标识:userid
密码:password
单击完成)干过瘾,没数据库,呵呵。(以上操作在“数据”透视图里面完成)
OK,到这里算是完成了对指定数据库的一个引用,接下来要把这个连接添加到我们的web应用中:
1. 在"数据库服务器"视图中展开BookData数据库连接,右键单击bookshop(jdbc:db2:bookshop),从弹出的相关菜单中选择导入至文件夹。
2. 在"导入"对话框中,单击浏览。
3. 在"文件夹选择"对话框中单击BookShopWEB,单击确定。
4. 单击完成。
(这个没办法截图啦,实在是没有这个环境。。。搞个MySQL的来骗骗它)
DSC0002.jpg

哈哈,成功了,
DSC0003.jpg

DSC0004.jpg

(估计这样导入之后该项目就可以利用这个连接名字来代替到数据库的连接了吧。)
DSC0005.jpg

以下参考IBM网站原文连接。没环境。
DSC0006.jpg

DSC0007.jpg

DSC0008.jpg

DSC0009.jpg
DSC00010.jpg
(图形化的数据库操作而已。。。。。。不过挺强。)

不过利用图形化来进行Insert页面构造代码会是这样:
INSERT INTO
   tcd002
   (
      id,
      "Name",
      "Status"
   )
   VALUES
   (
      :id,
      :name,
      :status
   )
  有点像是本机动态SQL。
DSC00011.jpg

DSC00012.jpg

其中的BookInsertView.jsp页面关键代码大致如下:




DSC00013.gif <%--Get host variables--%>
<%String inputid = (String) request.getParameter("id");  

String inputf_Status_ = (String) request.getParameter("f_Status_");  

String inputf_Name_ = (String) request.getParameter("f_Name_");  
%>

<%-- Connect to the database --%>
<%! com.ibm.db.beans.DBConnectionSpec dsSpec = null; %>
<%
if (dsSpec == null) {
%> <dab:driverManagerSpec id="BookConnection" scope="page"
userid='<%=config.getInitParameter("username")%>'
password='<%=config.getInitParameter("password")%>'
driver='<%=config.getInitParameter("driverName")%>'
url='<%=config.getInitParameter("url")%>' /> <%
   dsSpec = BookConnection;
}
%>

<%--Execute the Insert Statement--%>
<dab:modify id="insert_statement" connectionSpecRef="<%=dsSpec%>">
<dab:sql>
      INSERT INTO tcd002 ( id, "Name", "Status" ) VALUES ( :id, :name, :status )
   </dab:sql>
<dab:parameter position="1" type="CHAR" value="<%=inputid%>" />
<dab:parameter position="3" type="CHAR" value="<%=inputf_Status_%>" />
<dab:parameter position="2" type="VARCHAR" value="<%=inputf_Name_%>" />
</dab:modify>

Number of rows updated:

<jsp:getProperty name="insert_statement" property="updateCount" />

生成的com.bookshop.web.BookController代码如下:


package com.bookshop.web;
/**************************************************************
*Description - Book Front Controller
*
* The Controller is the initial point of contact for handling a request.  
* Place in this class any services you would like to do on every request
* (Logging, Dubuging, Authentication DSC00014.gif )
*/

// Imports
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BookController extends HttpServlet implements Serializable {
    /**************************************************************
    * Initializes the servlet
    * @param config The servlets configuration information
    */
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        //Place code here to be done when the servlet is initialized
    }

    /***************************************************************
    * Destroy the Servlet
    */
    public void destroy() {
        //Place code here to be done when the servlet is shutdown
        //Destroy the database connection
    }

    /***************************************************************
    * This method is run once for each request.
    * @param request The incoming request information
    * @param response The outgoing response information
    */
    public void performServices(
        HttpServletRequest request,
        HttpServletResponse response) {
        //Place any code here that you would like to run on every request
        //Logging, Authentication, Debugging
    }

    /***************************************************************
    * Process both HTTP GET and HTTP POST methods
    * @param request The incoming request information
    * @param response The outgoing response information
    */
    public void performTask(
        HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
        String nextPage;
        try {
            //Perform any specialized sevices
            performServices(request, response);

            //Get the web page associated with the command in the request
            nextPage = getInitParameter(request.getParameter("command"));

        } catch (Exception ex) {
            //If an exception is thrown serve the error page
            nextPage = getInitParameter("error_page");
        }
        //Forward the request to the next page
        dispatch(request, response, nextPage);
    }

    /***************************************************************
    * Process incoming requests for a HTTP GET method
    * @param request The incoming request information
    * @param response The outgoing response information
    */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        performTask(request, response);
    }

    /***************************************************************
    * Process incoming requests for a HTTP POST method
    * @param request The incoming request information
    * @param response The outgoing response information
    */
    public void doPost(
        HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
        performTask(request, response);
    }

    /****************************************************************
    * Dispatches to the next page
    * @param request The incoming request information
    * @param response The outgoing response information
    * @param nextPage The page to dispatch to
    */
    public void dispatch(
        HttpServletRequest request,
        HttpServletResponse response,
        String nextPage)
        throws ServletException, IOException {
        RequestDispatcher dispatch = request.getRequestDispatcher(nextPage);
        dispatch.forward(request, response);
    }
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-122305-1-1.html 上篇帖子: IBM Robocode Java学习利器(1)Robocode 入门 下篇帖子: IBM Cognos FM Determinants
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表