简体   繁体   中英

how to create stored procedure in mysql for java?

Here is my code:

 DELIMITER $$
    begin
    declare var a int;
    set a="select biology from app.students where studname="ganesh";
    select concat('the student name is' a);
    end$$

I want to create storeprodure in mysql for java. In the above code i gave anything after begin it shows error. I am not well in stored procedure.

Try this,you had mistake in "ganesh" and also in concat function , missing

DELIMITER $$
        begin
        declare var a int;
        set a="select biology from app.students where studname='ganesh'";
        select concat('the student name is', a);
        end$$

Just create the stored procedure in the MySql workbench exactly the same as you normally would. It doesn't matter that you are calling it from Java or anywhere else. Your stored procedure looks very messy and makes very little sense though, so I think you need to work on that!

Try just using the query analyzer and build the query not inside a stored procedure first.

Once the statement is written embed it in a stored procedure and then check you can still call it and it works from query analyzer.

Once the stored procedure is written you can just use a PreparedStatement to call it exactly the same as for any other SQL statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM