Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa SQL textfields and update
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


raven
textfields and update
2 Answer(s)      6 years and 2 months ago
Posted in : SQL



Advertisement
View Answers

September 22, 2008 at 11:20 AM




Hello Friend

As per ur 1st Q: Read the data from database and store into a list or arraylist (as per ur requiement);
pass the list into jsp page, iterate there and display.

In Second Q, u not clarify under which basis u want to update database?
can u clarify?

Thanks
Rajaniakant


September 22, 2008 at 11:29 AM


Hi friend,


Code to update record retieve at the Same time:

Some points to be remmeber:

1.Create a "process.jsp" file to update and retrieve record from database.
2.Using set the arraylist in the request parameter and forward to next page.

"process.jsp"

<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%

String userName = request.getParameter("userName");
String password = request.getParameter("password");
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");

System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "user_register";
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String userPassword = "root";

java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);

String strDateNew = sdf.format(now) ;


try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,username,userPassword);
Statement st = conn.createStatement();
Statement stmt = conn.createStatement();

String strQueryUpdate = "update user_register set first_name='"+first_name+"',last_name='"+last_name+"' where username='"+userName+"' and password='"+password+"'";

int i = st.executeQuery(strQuery);

String strQuery = "select * from user_register";
//out.println(strQuery);
ResultSet rs = st.executeQuery(strQuery);

ArrayList al = new ArrayList();

ArrayList arList;
while(rs.next())
{
arList = new ArrayList
String first_name= rs.getString("first_name");
String last_name= rs.getString("last_name");
al.add(first_name);
al.add(last_name);

arList.add(al);
}

request.setAttribute("arList",arList);
String nextJSP = "/home.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
conn.close();

} catch (Exception e) {
e.printStackTrace();
}
%>

Display record from database:

"home.jsp"

<%

List arlist = (ArrayList)request.getAttribute("arList");
Iterator itr = arlist.iterator();
Iterator itrrecord;
while(itr.hasNext())
{
Arraylist alrecord = (ArrayList)itr.next();

itrrecord = arlist.iterator();
while(itr.hasNext())
{
out.println(itr.next());
}
}
%>

Thanks


For read more details to visit....

http://www.roseindia.net/servlets/web-application.shtml

Thanks




Related Tutorials/Questions & Answers:
textfields and update - SQL
textfields and update  how can i retrieve a table from a database and put in on the textfields using jdbc?and at the same time update the items on the database
textfields and update - SQL
textfields and update  how can i put retrieved table from a database to the textfields using jdbc?and at the same time update the items on the database..   Hello Friend As per ur 1st Q: Read the data from
Advertisements
labels,textfields,buttons
labels,textfields,buttons  how to set the labels,textfields,buttons at certain positions such that we can add them without layout managers? my program is to design a login page with image and these labels at exact positions
making of dynamic textfields using swings
making of dynamic textfields using swings  How to make dynamic textfields using java swings
making of dynamic textfields using swings
making of dynamic textfields using swings  how to crate dynamic texfields by clicking on button
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
update
update  Predict and justify the output of the following code snippet written by the developer to update the Status table: String str = "UPDATE m...://localhost:3306/roseindia", "root", "root"); String str = "UPDATE Status SET
Background color blocks all labels and textfields
Background color blocks all labels and textfields  I added background color but I dont see textfields and labels anymore, please help. What am I missing? (" JFrame f = new JFrame(); SchoolOption f1 = new SchoolOption(); Color c
Use Map to display file data into textfields
Use Map to display file data into textfields Collection framework allows... textfields which are generated at run time. In text file, we have written... = new JButton("Put file data into TextFields"); JPanel p = new JPanel
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?  ...(); } This method doesn't work. I tried with quotes for textfields, without them. The setters require other parameters, not textfields. I tried to cast them
update profile
update profile  coding for update profile
how to update
how to update   conditional update
update image
update image  sir, I want to do update image into database
create a table in access2007 from gui application using textfields and combox
create a table in access2007 from gui application using textfields and combox  I want to create a table in ms access 2007 from gui application in which when i click create button the table should get created based on textfield
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
to update the information
to update the information   sir, i am working on library mgt project. front end is core java and backend is ms access.i want to open,update the information through form.please send me code earliar
update database
update database  hi.. i want to know how the valuesof database can be updated in the jsf-jpa framework when the drop down button is clicked the data... that can be done there then by pressing the update buutton the value can be updated
Update value
Update value  How to update value of database using hibernate ?   Hi Samar, With the help of this code, you will see how can update database using hibernate. package net.roseindia.DAO; import
to update the information
update the information   sir, i am working on library mgt project. front end is core java and backend is ms access.i want to open,update the information through form.please send me code earliar.   Please visit
Update - JDBC
is what I used to update normally. It works. Please assist me. Thanks...("jdbc:odbc:Biu"); stat = con.prepareStatement("Update Biu SET itemcode...; Step1: Retrive the column value which one you want to update and store
Update statement
Update statement  I create a access database my program When I click add button bata are adds to the my data base but when i click update button my database is not update I write this program using 3 differfnt notepad pages MY
update jsp
update jsp  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC...;/Controller"> <center> <input type="hidden" name="page" value="update"/>
data update
edit/update data and saved them into that table again
update php cpanel
update php cpanel  update php cpanel
update mysql database
update mysql database  update mysql database
coding for update profile
coding for update profile  coding for update profile
code to enter values in multiple textfields throught 10 buttons (0-9) (as if a calculator programe)
code to enter values in multiple textfields throught 10 buttons (0-9) (as if a calculator programe)  how can i enter values in two different textfield's through 10 different buttons.?? as we saw a online calculator type
Update not working in hibernate.
Update not working in hibernate.  Update not working in hibernate
how to update image in php
how to update image in php  how to update image in php
 

 

 

DMCA.com