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

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

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);
  }
}

}

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);
  }
}

}









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
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
i have an ques. of advanced java
i have an ques. of advanced java  write a wap to implement AWT by login form
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 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
When finally block is not executed in Java?
When finally block is not executed in Java?  Hi, I have read that finally block is always executed in Java. But I want to know if there is any conditions when finally is not executed. When finally block is not executed in Java
When finally block is not executed in Java?
When finally block is not executed in Java?  Hi, I have read that finally block is always executed in Java. But I want to know if there is any conditions when finally is not executed. When finally block is not executed in Java
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
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
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  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
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
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
Java Program - JDBC
Java Program  A java program that display in in a table in JTable
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
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
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
I have crude application
I have crude application   I have crude application, how to load into this roseindia.net
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
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
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
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
I need add my java program with a picture.
I need add my java program with a picture.  Good evng Frnds Friends i created 1 jar file in my desktop. I need add this program with 1 picture. Whenever the user double clicking on that picture The program must start instead
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
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
which tag i have to use - Java Server Faces Questions
which tag i have to use  Hi All, I have one Question Regadding Jsf. when i clicked on one dropdown list box.when i select one item it should.... for that what tag i have to use.please help me. Thanks, Puppy.  use
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
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
I developed a simple java web project in Struts now If I have to import the project in Eclipse Indigo how can I do it
I developed a simple java web project in Struts now If I have to import the project in Eclipse Indigo how can I do it   I developed a simple java web project in Struts now If I have to import the project in Eclipse Indigo how
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
jdbc program
jdbc program   Write a program to update the salaryRs.6000/- for an employee name like â??P. Ramuâ?? using prepared statement
"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
Jdbc and Socket Program - JDBC
Jdbc and Socket Program  Sir, I would like to get a program i... in a database.Now we create another program 4 client-server such that the sever's database is updated everytime we enter username and password in client program
I have problem in my Project
I have problem in my Project  Dear Sir, i have problem in my project about Jtable i have EDIT JButton whenevery i was click on edit he is display all data from database but i want to select any row
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.   ConnectionProvider.java import java.util.*; import... class=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@localhost:1521:xe user
java program run on thml page?
java program run on thml page?  how to run java program on html page using text area
i have a problem in spring - Spring
i have a problem in spring  spring Aop: how to configure proxyfactorybean in xml file for providing advices for one particular class
doubt on synchronized block in java
. I think you got my doubt. I request you to clarify my doubt based on below...doubt on synchronized block in java  Hi ! some people are feeling... am a beginner.I am learning java with out any teacher.I need your valuable
i need program or code for this program
i need program or code for this program  out should be in this form 1 2 3 4 5 6 3 5 7 9 11 8 12 16 20 20 28 36 48 64 112
Doubt on Segmentation - Java Beginners
Doubt on Segmentation  Hi .. ImageProcessing.. How to segment the each and every characters from the bitmap image Consider for an example... WORD - Segmented Characters Visualc++ ------ > V|i|s|u|a|l|c
doubt this
doubt this  what is the use of "this" and "super" keyword
i have developed the application in jsp(front-end -jsp,business logic-jsp).it is very slow when accessing the page - JSP-Servlet
i have developed the application in jsp(front-end -jsp,business logic-jsp).it is very slow when accessing the page  i have developed the application in jsp only.i did not use any classes.application is very slow when access

Ads