problem in database

Ads
 

problem in database

thanks for web site.

I want change this code to insert data into PostgreSql database using jsp,servlets.
 but i getting output "Record has been inserted",

1.no data in the table(sample)

public class ServletUser extends HttpServlet
{

try {
  Class.forName("org.postgresql.Driver");

  PreparedStatement pst = connection.prepareStatement("INSERT into sample VALUES(?,?)");

  pst.setString(1,username);
  pst.setString(2,pass);

  int numRowsChanged = pst.executeUpdate();
   if(numRowsChanged!=0){  
             out.println("<br>Record has been inserted");  
           }  
           else{  
             out.println("failed to insert the data");  
            }  
  pst.close();
}
catch(ClassNotFoundException e){
  out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e){
  out.println("SQLException caught: " + e.getMessage());
}
catch (Exception e){
  out.println(e);
}
finally {
  // Always close the database connection.
  try {
    if (connection != null) connection.close();
  }
  catch (SQLException ignored){
    out.println(ignored);
  }
}

 }
}

//AddForm.jsp

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Data To DataBase</title>
</head>

<body>

<form name="TestForm" method="post" action="/ServletUser">
  <label>
  <label>Emp_Id</label>&nbsp;&nbsp;&nbsp;&nbsp;     
  <input type="text" name="empid" />
  </label>

    <label>Emp_Name
    <input type="text" name="ename" />
    </label>

   &nbsp;&nbsp;&nbsp;<input type="submit" name="Submit" value="Submit" /> 
</form>

</body>

</html>

//web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>
    AddDataBase</display-name>
    <servlet>
        <servlet-name>ServletUser</servlet-name>
        <servlet-class>data.ServletUser</servlet-class>
    </servlet>

&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;ServletUser&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;

&lt;welcome-file-list&gt;
    &lt;welcome-file&gt;AddForm.jsp&lt;/welcome-file&gt;
&lt;/welcome-file-list&gt;


</web-app>

//Database name: postgres

CREATE TABLE sample
(
  username character(20),
  pass character(15)
)
View Answers

Ads









Related Tutorials/Questions & Answers:
problem in database
problem in database   thanks for web site. I want change this code to insert data into PostgreSql database using jsp,servlets. but i getting...){ out.println("Couldn't load database driver: " + e.getMessage()); } catch
database problem
database problem  I did connect my jsp page to database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse from the jsp page where all the data field has been showed
Advertisements
database problem
database problem  I did connect my jsp page to database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse from the jsp page where all the data field has been showed
Oracle 9i database problem
Oracle 9i database problem  Hi Somebody has given the solution but i.............,send reply immediately. I have a problem in Oracle9i .I have installed... what i created .But after closing the SQL+ ,the problem started.When i again opened
Database fetching problem
Database fetching problem  I have multiple database table and want to get all records in one object how can i do this.Pls guide
database connectivity problem
database connectivity problem  what if client dont have database with them then what is other way to run successfully our programm   Please visit the following link: http://www.roseindia.net/jdbc
Problem in accessing data from Database
Problem in accessing data from Database  hi..... i'm making a project on servlet and jsp with ms access 2007 at the backend. One field in my database... someone plz help me out with this problem
problem in setting the values from database
problem in setting the values from database  hello friends, can anyone help me?? I am facing this problem for past one week. I could't set the values from database. here is the code: private JTextField getJTextField1
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help... be save in the database. and the image will also save in the desired folder. i have no problem in saving the image in the folder, my problem is it can't save
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help... be save in the database. and the image will also save in the desired folder. i have no problem in saving the image in the folder, my problem is it can't save
problem in selecting second arraylist from mysql database
problem in selecting second arraylist from mysql database  Hi... in mysql database. In the below program , i have hard-coded that second list, but i want second list to be dynamic from database. Please, help me out. Thank
getting problem in storing & retrieving value in database
getting problem in storing & retrieving value in database  Hello everyone i am doing a project where my back end is ms access & i want to store value like 5353250214 so if i store it as long int in access it wont take it &
Problem in populating tableview with database data using javafx MVC architecture.
Problem in populating tableview with database data using javafx MVC... architecture. Here i want to populate tableview as it is with database table data. Here the problem is i am getting all elelments of every row in each column
Problem in populating tableview with database data using javafx MVC architecture.
Problem in populating tableview with database data using javafx MVC... architecture. Here i want to populate tableview as it is with database table data. Here the problem is i am getting all elelments of every row in each column
please help me solve this problem when i am create database connection using servlecontext
please help me solve this problem when i am create database connection using servlecontext  hi... I have create a database connection using... understand what is the problem .... the code are as follows. the servlet context
Null pointer exceptation-Java Servlet web application,Problem connecting with MYSQL database
Null pointer exceptation-Java Servlet web application,Problem connecting...,since i try to configure this out for 1 week,i dont find any solution for my problem... the project in WAR file and then i upload to my hosting. The problem come when my
database
database  database
database
database  database application
database
database  the code for initializing the database connection
database
database  i want to let the user select the name of database and then delete that database.......im doing project in swings netbeans
database
database  use of hyperlink to show the data from database
database
database  i need to insert time in my database. i need a code to insert time in my database. its very urgent
problem on php
problem on php   l have five tables and build them as forms and link between them php and database and i want to build query between them plz help me soon   PHP MySQL Tutorials
database
database  im doing my project in netbeans swings...wn a user wants to create a database from the gui...i want to display an error msg if a database with that name already exists and if it does not exist new database should
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  I wanted to know if it is possible to create a database in mysql by letting the user enter the name of the database in swing gui..im doing my project in netbeans...Thank You
database
database  I wanted to know if it is possible to establish database connection on a remote pc with mysql using java swings from netbeans and then create a database on the remote pc.... Kindly help me
DATABASE
DATABASE  How can i get combo box values from database?? or how can i get values in the drop down menu of the html which is similar to dat of combo box in java - from database
Database
Database  How to represent data from database in a tree?   Please visit the following link: Retrieve data from database in tree using Java Swing

Ads