简体   繁体   English

如何在MySQL中为Java创建存储过程?

[英]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. 我想在mysql中为Java创建storeprodure。 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 试试这个,你在"ganesh"和concat函数中都出错了,丢失了

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. 只需像通常一样在MySql工作台中创建存储过程即可。 It doesn't matter that you are calling it from Java or anywhere else. 从Java或其他任何地方调用它都没关系。 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. 写入存储过程后,您就可以使用PreparedStatement对其进行调用,就像对其他任何SQL语句一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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