Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

I have a doubt on java jdbc .The program is executed but empty page came

Ads

 
 

Share on Google+Share on Google+

chundru suresh
I have a doubt on java jdbc .The program is executed but empty page came
1 Answer(s)      5 years and a month ago
Posted in : JDBC

import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

public class DBConnection extends HttpServlet { Connection con; Statement st; public void init()throws ServletException { try { Class.forName("oracle.jdbc.driver.OracleDriver"); con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","krishna","nagamani"); st=con.createStatement();

      if(con!=null)
      {
         System.out.println("Connection is Created...........");
      }
    }
    catch(Exception e)
    {
        System.out.println("init() Exception is  : "+e );
    }
}  //init()

public void doGet(HttpServletRequest request,HttpServletResponse response)throws  ServletException,IOException
{
  try
  {
      PrintWriter pw=response.getWriter();
      String myname=request.getParameter("myname");
   //    pw.println("hello "+myname+"  Connection is Created...........");
      if(st!=null)
      {
         pw.println("hello "+myname+"  Connection is Created...........");
      }
  }
  catch(Exception e)
  {
      System.out.println("doGet() exception is : "+e);
  }
}

}

Ads
View Answers

June 4, 2012 at 3:49 PM


We have modified your code. The code connects the java servlet with oracle database.

import java.io.IOException;
import java.io.PrintWriter; 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement; 
import javax.servlet.*;
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DBConnection extends HttpServlet { 
    Connection con; Statement st;
    public void init(ServletConfig config)throws ServletException {
        try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","krishna","nagamani" ); 
    st=con.createStatement();

      if(con!=null)
      {
         System.out.println("Connection is Created...........");
      }
             super.init(config);
    }
    catch(Exception e)
    {
        System.out.println("init() Exception is  : "+e );
    }
}  

public void doGet(HttpServletRequest request,HttpServletResponse response)throws  ServletException,IOException
{

  try
  {
      PrintWriter pw=response.getWriter();
      String myname=request.getParameter("myname");

      if(myname!=null)
      {
         pw.println("hello "+myname+"  Connection is Created...........");
      }
  }
  catch(Exception e)
  {
      System.out.println("doGet() exception is : "+e);
  }
}

}

Ads









Related Tutorials/Questions & Answers:
I have doubt in jsp file.
I have doubt in jsp file.  I have doubt in jsp file. In a jsp file, there should be two buttons. One is start and other is stop. When we click on start then only stop should be enabled. Other wise it should be disabled. When
I have a doubt regarding action - Struts
I have a doubt regarding action   hi, I have doubt regarding struts,I got response through jsp and once again it redirecting to action..., Please check Action Mapping in the struts-config.xml. If you have any problem
Advertisements
i have problem in that program - JavaMail
i have problem in that program  1. Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number... paradigms of Java. Use JDBC to connect to a back-end database.  Hi Friend
doubt in inheritance program - Java Beginners
doubt in inheritance program  how will we get the result 6 2 5 in the inheritance program in the given example i got 6 &2 but i am confused about 5
i have problem in that program sir - JavaMail
i have problem in that program sir  1.Develop multi-threaded echo server and a corresponding GUI client in Java
doubt in my program code - Java Beginners
doubt in my program code  i have developed a web browser with the help of standard widget toolkit(swt) and java. i creted some buttons such as GO... we can see as the name of all the buttons.my question is i need to change
java program - JDBC
java program  i have a DBschema, in that i have schema name and set of tables as fields, in this case i have three tables, i need a java program... out. i have used mysql for connecting to the database.  Hi friend
i have an ques. of advanced java
i have an ques. of advanced java  write a wap to implement AWT by login form
i have problem in that program to my assignment sir - JavaMail
i have problem in that program to my assignment sir   Develop a programmer's editor in Java that supports syntax-highlighting, compilation support, debugging support, etc
In Java I have append to an existing string efficiently
In Java I have append to an existing string efficiently  Hi, In a Java program I have to append to a existing string more efficiently so... of the cases. Check the example at: How To Append String In Java?. Thanks
i have no programming knowledge is it possible for study java?
i have no programming knowledge is it possible for study java?  hello sir i have no programming knowledge is it possible to study java and jsp and servlet and struts.if it is then how i schedule for this and how to study
I have one small doubt , does this code read Microsoft Office suit file format data such as .doc , .docx etc ?
I have one small doubt , does this code read Microsoft Office suit file format data such as .doc , .docx etc ?  import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class ReadFileExample
Java Program - JDBC
Java Program  A java Program that display data from a Table...("jdbc:odbc:access"); String sql = "Select * from data"; Statement stmt... md = rs.getMetaData(); int columns = md.getColumnCount(); for (int i = 1; i
jdbc connection to java program code - JDBC
jdbc connection to java program code  i want a simple java program... and update records in database and show in program output? please take a simple table structure as an example so that i am able to understand logic
Java Program - JDBC
Java Program  A java program that display in in a table in JTable
Java Program - JDBC
Java Program  Write a Java Code using swings and display records from...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:access...=""; for(int i=0;i  continue... previousRecord.addActionListener(new
Java Program - JDBC
Java Program  A java program that display data in textfields and having buttons for move next, move previous,move last,move first using JFrame
Doubt in using combination of JSP page and Java class. - JSP-Servlet
Doubt in using combination of JSP page and Java class.   I've got... youfor replying. I didn't used struts,insted i went with servlet and Java Class... it to another jsp page that i used to display those buttons with their name
is it necessary to have depth knowledge on servlets jsp and jdbc to learn java frameworks
is it necessary to have depth knowledge on servlets jsp and jdbc to learn java... works i.e., struts,hibernate and spring.. i dont have that much depth or practical knowledge..my question is do i need to have depth knowledge of servlets jsp
java doubt
exception handler. For instance in the above given program we have used... the message which we want to be printed. For instance in the above example we have used... use throws keyword. Point to note here is that the Java compiler very well knows
Hello Sir I Have problem with My Java Project - Java Beginners
Hello Sir I Have problem with My Java Project  Hello Sir I want Ur Mail Id To send U details and Project Source Code, plz Give Me Ur Mail Id
InputSecret field becomes empty when page is reloaded
InputSecret field becomes empty when page is reloaded  How to fix the problem when h:inputSecret field becomes empty when page is reloaded
In JSP page, inside a javascript function, can I place a java code using scriptlet tag?
In JSP page, inside a javascript function, can I place a java code using...() in jsp page. In a separate java file, in a method checkListValue(), I am doing... to check whether a particular list is empty or not. If its not empty, I need
i have problem with classnofounderror
i have problem with classnofounderror   import java.sql.*; public class Tyagi { public static void main (String args[])throws SQLException... = DriverManager.getConnection("jdbc:oracle:thin:@localhost:8080:oracle", "System", "manager
i have problem with classnofounderror
i have problem with classnofounderror   import java.sql.*; public class Tyagi { public static void main (String args[])throws SQLException... = DriverManager.getConnection("jdbc:oracle:thin:@localhost:8080:oracle", "System", "manager
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
I have crude application
I have crude application   I have crude application, how to load into this roseindia.net
how do i write a java program for this??
how do i write a java program for this??  ‚??Ask the user if they have a dog. If ‚??yes‚??, ask the user how old is and compute the dog‚??s age... as the source for your calculations. You only have to account for input from this table
I have need to help
I have need to help  Write a program that, for four points A, B, C and P, draws a triangle formed by ABC and a small cross showing the position of P; and displays a line of text indicating which of the following three cases
what is wrong in this program?I have netbeans 7.0 & jdk 7. please do corrections.
what is wrong in this program?I have netbeans 7.0 & jdk 7. please do corrections.  import java.io.*; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.List
"Doubt on Swing" - Java Beginners
"Doubt on Swing"  Hi Friend.... Thanks for ur goog Response.. i need to create a GUI Like... pic1.gif RadioButton pic2.gif RadioButton Pic3.gif RadioButton If we have select d appropriate radio