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.
- StringProc="{Call procname (?,? )}";
- CallableStatementStat=Con. PrepareCall (proc );
- // 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.
- Stat. setString (1, 'paravalue '); // set the parameter value
- // If the second parameter is set as out
- Stat. registerOutParameter (1, java. SQL. Types. VARCHAR); // set the parameter type
- Stat.exe cute ();
- StringParaValue=Stat. GetString (2); // obtain the out parameter value.
- For example:
- <% @ PageImport="Java. SQL .*"%>
- <% @ PageImport="Java. text .*"%>
- <% @ PageContentType="Text/html; charset = GB2312"%>
- <% @ IncludeFile="Opendata. jsp"%>
- <%
- StringStrSQL="{Call pdrivertotal (,)}";
- CallableStatementStmt=Con. PrepareCall (strSQL );
- Stmt. setString (1, "2005-08-20 ");
- Stmt. setString (2, "2005-10-01 ");
- Stmt.exe cute ();
- %>
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.
- StringProc="Exec process name"+ Parameter 1 + "," + parameter 2;
- StatementStat=Con. CreateStatement ();
- ResultSetRs=Stat. ExecuteQuery (proc );
For example:
- // Used in JSP
- <%
- StatementStat=Con. CreateStatement ();
- ResultSetRs=Stat. ExecuteQuery ("zyfproc 20 'name '");
- // Zyfproc: stored procedure name 20: int type parameter, name: varchar type parameter
- %>
- // Use jstl label in jsp
-
- <SQL: update Var="Proc" SQL="Exec jproc ?,? " DataSource="$ {Ds }">
-
- <SQL: param Value="$ {Param. hid }"/>
- <SQL: param Value="$ {Param. sid }"/>
-
SQL: update>
The above process is to use storage in JSP JSTL
- Summary of redirection Technology in Servlet and JSP
- Notes for connecting JSP to ORACLE databases
- Brief Introduction to advanced operations on JSP Databases
- Solutions to Jsp output of excel documents and Chinese garbled characters
- How to solve the problem of garbled JSP page display