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)      4 years and 10 months 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);
  }
}

}









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
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 - 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
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 an ques. of advanced java
i have an ques. of advanced java  write a wap to implement AWT by login form
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
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 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 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
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
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 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
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
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
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
java program run on thml page?
java program run on thml page?  how to run java program on html page using text area
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
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
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
"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
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
I have crude application
I have crude application   I have crude application, how to load into this roseindia.net
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
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads