ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Java J2EE  >>  Java Related  >>  JDBC
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
I have getting problem to calling stored procedure from 
Mysql through JSP. Please help me.
 Question Submitted By :: Tathagata
I also faced this Question!!     Rank Answer Posted By  
 
  Re: I have getting problem to calling stored procedure from Mysql through JSP. Please help me.
Answer
# 1
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 ?    1 Yes 0 No
John Abraham
 

 
 
 
Other JDBC Interview Questions
 
  Question Asked @ Answers
 
What is Type-2 Driver and when this driver is used?  2
Difference between Generic Servlet and HTTP Servlet?  7
What is static Synchronized method in JDBC API? Give an example? R-Systems1
What are the different types of statements?  2
what is callable statement? Infogain5
how you will execute the many tables data Wipro1
Hi........I need to create a dropdown box using java.....this box should show the values that should be taken from the database...... Thank you....  1
How a driver can be loaded?  1
how to use CallableStatement? specially how to use their index given ..  1
What is Type-3 Driver and when this driver is used? Wipro3
What are different types of transactions?  1
what does batchUpdate does? HCL5
what is rowset? Marlabs3
How many isolation levels are supported in JDBC and what are they?  1
what are the Different types of exceptions in JDBC?  1
write down exceptions those appear in java programs when u write JDBC Programs?  2
Diff bet.. Function and Trigger? Logica-CMG3
What is meant by a ResultSet?  3
What is de-normalization?  1
Can the JDBC-ODBC Bridge be used with applets?  1
 
For more JDBC Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com