I have getting problem to calling stored procedure from
Mysql through JSP. Please help me.



I have getting problem to calling stored procedure from Mysql through JSP. Please help me...

Answer / john abraham

for example first create database name test which has one
one table name as johncheck which has one fieldname name1
after tat u have to create stored procedure like this

DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`johnchecksp` $$
CREATE PROCEDURE `johnchecksp`(in name1 varchar(50))
BEGIN
insert into johncheck values(name1);
select * from johncheck;
END $$

DELIMITER ;
after you created stored procedure then you have to write
the below coding
this is the jsp code using eclipse

<%@ page language="java" import="java.util.*,java.sql.*"
pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath =
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'select.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords"
content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>
<%!
CallableStatement calstat;
ResultSet rs;
String s1="shiju";
<body>
This is my JSP page. <br>
<%try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn =
DriverManager.getConnection("jdbc:mysql://192.168.1.7:3306/test","java@livicsa",
"Livicsa");
out.println("connected");
calstat=conn.prepareCall("{CALL john_select(s1)}");
out.println("welcome");
//calstat.setString(1,s1);
rs = calstat.executeQuery();
while(rs.next())
{
String name2=rs.getString(1);
out.println("the calue is"+name2);
}
conn.close();
calstat.close();
out.println("Your data has been inserted into table.");
}
catch(Exception e)
{
out.println("the exception is"+e);
}
%>
</body>
</html>

here test is the database name and java@livicsa is username
Livicsa is password .. u have to give your sql username and
password in replace of that place

i hope this code will help you

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More JDBC Interview Questions

Is oracle client required for jdbc connection?

0 Answers  


What is Normalization?

2 Answers   Accenture, Atos Origin,


Does jdbc require oracle client?

0 Answers  


What are the steps to connect to the database in java?

0 Answers  


How is database middleware used to access legacy databases?

1 Answers  






Hi my doubt is that preparedStatement is a interface means which has no implemenation.plz go thru the code below String sql = "SELECT * FROM movies WHERE year_made = ?"; prest = con.prepareStatement(sql); prest.setInt(1,2002); ResultSet rs1 = prest.executeQuery(); Now setInt and executeQuery how it works since it is interface it does not have implementation how it works, how executeQuery returns result from database as executequery method has no implementation even in Statement interface.

4 Answers   Cybermate, Hexaware,


What is odbc and jdbc?

0 Answers  


What are the differences between resultset and rowset?

0 Answers  


What is the function of setautocommit?

0 Answers  


How does jdbc work?

0 Answers  


Does jdbc use odbc?

0 Answers  


What is jdbc resultsetmetadata interface?

0 Answers  


Categories