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 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









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 problem - WebSevices
simple database connectivity code. if you have any problem then send me detail...Database problem  Hello, How i connect my database file& tables to Zend library file. In which library file i should change that code
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
database problem - JDBC
database problem  I installed Oracle 8.05 on Redhat 6.1 linux. If i fire up SQl plus seesion from the localhost, i can login succsfully as any user, If i go to a win98 or NT machine, I will get the following error after trying
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 Jsp and database - Development process
Problem in Jsp and database  Hi, How can I reterive values from database and display them in teextboxes so that when the user select the UPDATE... to the database itself . Thanks in advance.  Hi Friend, You can use
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
Problem with JRadioButton and Access Database - Java Beginners
Problem with JRadioButton and Access Database  Hello sir ,Here I have... in Access Databse, I want to store course type in to database and also other fields...(); JOptionPane.showMessageDialog(p1,"Data is successfully inserted into database."); con.close
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 &
Facing Problem to insert Multiple Array values in database - JSP-Servlet
facing the problem while inserting the data in database. iam using the MsAccess Database My Database structure is Like iam using tow tabel ,CustomerDetails...Facing Problem to insert Multiple Array values in database  Hai
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
Problem with Double type Value in Access Database - Java Beginners
Problem with Double type Value in Access Database  Hello sir I have... Mobile Number with MS access Database,plz Help Me Sir.   Hi Friend...+")"); JOptionPane.showMessageDialog(null,"Data is successfully inserted into database."); ResultSet rs
problem from registering a data in database with servlet - JSP-Servlet
problem from registering a data in database with servlet  Hi Rose, i created a servlet to validates ten user details in the database, if present... the user's details and submit into database. but it'll first insert the details
Problem insert data into database using servlet n javabean - Java Beginners
Problem insert data into database using servlet n javabean  I created a servlet for registration proses I got a problem compiling my servlet.. (incompatible type: int and required: java.lang.ResultSet) can anyone help me
i am getting the problem when i am downloading the pdf file from oracle 10g database - Struts
i am getting the problem when i am downloading the pdf file from oracle 10g... into datbase and download the pdf file from database. but when i created the pdf file from the struts application(itext.jar),it is uploading into database
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
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
Database
Database  I am working in jsf2.Fro a demo i created database in ms access.no wi want to retrive a record from database for a particular data.I need help as I am stuck
Database
Database  from java code i have to retrieve some data from a database, which is present in a different timezone. Scenario :- My database... in database timezone is 9PM 15APR2012. I want to retrieve something from database
Database
Database  Can i get a code for database connectivity Myeclipse 3.3 to MySql manager 2005
DATABASE
DATABASE  I can't send different information from different form into a single table in my database
database
database  dateofbirth is not save into the database while i am enter from html browser.it shows as null.whats the reason
database
database  sir.. how we can uplaod the database in the data file(ms access)please send me a solution
database
database  how we ca upload the data in the database file(ms access
database
database  hi i want to develop one patient database can any one provide me the guide
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  In my project where u helped me to display the databases present im mysql database on the Jlist and then the respective tables in that database on another jlist and then the column names on another jlist I dont want
database
database  In my project,i want the user to specify the name of the database he wants to create in mysql and then also the name of the table along with the column names he wants in that database....Im doing my project in netbeans

Ads