如何在struts2中调用oracle的存储过程

时间:2013-07-11 17:11:58

标签: jdbc oracle10g

我想在下面的struts代码中调用oracle 10g的存储过程名称(mytable1)。怎么做?

    import java.sql.*;
    public class loginuser 
    {
    public String username;
    public String password;
    public String execute()
    {       

    Connection con;
    Statement stmt;
    ResultSet rs;
    try
    {

    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","Gaurav","oracle");
    stmt=con.createStatement();
    rs=stmt.executeQuery(" HOW TO CALL A PROCEDURE");

    }
    catch(ClassNotFoundException e)
    {

    }
    catch(SQLException ex)
    {
    }
    }
    public String getpassword()
    {
            return password;
        }
       public void setpassword(String m)
    {
            this.password = m;
    }

    public String getusername() {
    return username;
    }

    public void setusername(String username) {
    this.username = username;
    }
    }

以下是程序:

CREATE  or replace PROCEDURE mytable1 (tname varchar2)
is
stmt varchar2(1000);
begin
stmt := 'CREATE TABLE '||tname || '(username varchar2(20) ,password varchar2 (10))';
execute immediate stmt;
end;

0 个答案:

没有答案