Record the process of using storage in JSP JSTL

Source: Internet
Author: User

In Java, JSP and jsp jstl give a brief introduction to the general methods and simplest methods used in stored procedures. This document uses SQL server2000 as an example.

Use stored procedures in JSP JSTL

1. Standard usage of stored procedures in Java:

Various functions in stored procedures can be implemented. Compared with the simplest method, the out parameter and the returned value of the process can be obtained.
? Is the placeholder of the parameter. A question mark represents a parameter.

 
  1. StringProc="{Call procname (?,? )}";
  2. CallableStatementStat=Con. PrepareCall (proc );
  3. // If the first parameter is in, what is the description? The number should be in the English input method. This blog cannot enter a question mark in English.
  4. Stat. setString (1, 'paravalue '); // set the parameter value
  5. // If the second parameter is set as out
  6. Stat. registerOutParameter (1, java. SQL. Types. VARCHAR); // set the parameter type
  7. Stat.exe cute ();
  8. StringParaValue=Stat. GetString (2); // obtain the out parameter value.
  9. For example:
  10. <% @ PageImport="Java. SQL .*"%> 
  11. <% @ PageImport="Java. text .*"%> 
  12. <% @ PageContentType="Text/html; charset = GB2312"%> 
  13. <% @ IncludeFile="Opendata. jsp"%> 
  14. <%
  15. StringStrSQL="{Call pdrivertotal (,)}";
  16. CallableStatementStmt=Con. PrepareCall (strSQL );
  17. Stmt. setString (1, "2005-08-20 ");
  18. Stmt. setString (2, "2005-10-01 ");
  19. Stmt.exe cute ();
  20. %> 

2. The simplest method of stored procedures:

Idea: Execute the process as a normal SQL statement, that is, it is the same as the query and update statement. The execution process can be implemented and relevant datasets can be obtained. However, it cannot obtain the out output parameter of the process. This parameter is applicable in 90% of development scenarios.

 
  1. StringProc="Exec process name"+ Parameter 1 + "," + parameter 2;
  2. StatementStat=Con. CreateStatement ();
  3. ResultSetRs=Stat. ExecuteQuery (proc );

For example:

 
  1. // Used in JSP
  2. <%
  3. StatementStat=Con. CreateStatement ();
  4. ResultSetRs=Stat. ExecuteQuery ("zyfproc 20 'name '");
  5. // Zyfproc: stored procedure name 20: int type parameter, name: varchar type parameter
  6. %> 
  7. // Use jstl label in jsp
  8.  
  9. <SQL: update Var="Proc" SQL="Exec jproc ?,? " DataSource="$ {Ds }"> 
  10.  
  11. <SQL: param Value="$ {Param. hid }"/> 
  12. <SQL: param Value="$ {Param. sid }"/> 
  13. SQL: update> 

The above process is to use storage in JSP JSTL

  1. Summary of redirection Technology in Servlet and JSP
  2. Notes for connecting JSP to ORACLE databases
  3. Brief Introduction to advanced operations on JSP Databases
  4. Solutions to Jsp output of excel documents and Chinese garbled characters
  5. How to solve the problem of garbled JSP page display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.