Calling stored procedures and functions in the database in Java

Source: Internet
Author: User

public static void Main (string[] args)

{
Connection Conn =getconnection (URL,USER,PWD);
SYSTEM.OUT.PRINTLN ("Data connection succeeded");
CallableStatement Cs=null;
Try
{//Call a stored procedure in the database
CS =conn.preparecall ("{Callpro_deleteproducttype (?,?)}"); /pro_deleteproducttype is the name of the stored procedure to invoke, the first parameter is the shaping input parameter, the second parameter is the output parameter
Set input parameters for a stored procedure
Cs.setint (1, 24);
Sets the stored procedure return value type and executes
Cs.registeroutparameter (2,java.sql.types.varchar);
Cs.execute ();
Receives the return value and prints
String str = cs.getstring (2);
System.out.println (str); Calling database functions
CS1 = Conn.preparecall ("{? =call fun_str ()}"); //Where fun_str () is the function name,? is a placeholder for the return value Cs1.registeroutparameter (1,java.sql.types.varchar);   Cs1.execute ();  Stringstring1=cs1.getstring (1); SYSTEM.OUT.PRINTLN ("The result of the function call is:" +string1);
}
catch (SQLException e)
{
TODO auto-generated Catch block
E.printstacktrace ();
}
Finally
{//Close all connections
CloseAll (conn, CS, null);
}
}

Calling stored procedures and functions in the database in Java

Related Article

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.