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



Home Answers Viewqa Development-process Problem in Jsp and database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Rajendra
Problem in Jsp and database
2 Answer(s)      5 years and 7 months ago
Posted in : Development process



Advertisement
View Answers

April 18, 2009 at 11:34 AM


Hi Friend,

You can use the following code:

step1) Create databaseTable.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<title>display data from the table using jsp</title>
</head>
<body>
<FORM ACTION="insert.jsp" method="get" >
<%
try {
String connectionURL = "jdbc:mysql://localhost:3306/register";;
Connection connection = null;
Statement statement = null;
ResultSet rs = null;

Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
statement = connection.createStatement();
String QueryString = "SELECT * from registertable where user_id=1";
rs = statement.executeQuery(QueryString);
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<%
while (rs.next()) {
%>
<TR><TD>First Name: </TD><TD><input name="text2" type="text" value="<%=rs.getString(2)%>"></TD></TR>
<TR><TD>Last Name: </TD><TD><input name="text3" type="text" value="<%=rs.getString(3)%>"></TD></TR>
<TR><TD>Address: </TD><TD><input name="text4" type="text" value="<%=rs.getString(4)%>"></TD></TR>
<TR><TD>Email: </TD><TD><input name="text5" type="text" value="<%=rs.getString(5)%>"></TD></TR>
<% } %>
<%
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
out.println(ex);
} %>
</TABLE>
<input type="submit" value="Update">
</Form>
</body>
</html>


April 18, 2009 at 11:35 AM


cont...........

step2) create insert.jsp:

<%@ page import="java.sql.*" %>
<%
String text2=request.getParameter("text2");
String text3=request.getParameter("text3");
String text4=request.getParameter("text4");
String text5=request.getParameter("text5");
try {
String connectionURL = "jdbc:mysql://localhost:3306/register";;
Connection connection = null;
Statement statement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();

connection = DriverManager.getConnection(connectionURL, "root", "root");

statement = connection.createStatement();
int val = statement.executeUpdate("update registertable set firstName='"+text2+"',lastName='"+text3+"' ,address='"+text4+"',email='"+text5+"' where user_id=1");
statement.close();
connection.close();
}
catch(Exception e){
out.println(e);
}
%>

Thanks


Related Tutorials/Questions & Answers:
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
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
Facing Problem to insert Multiple Array values in database - JSP-Servlet
Facing Problem to insert Multiple Array values in database  Hai friend , Iam beginner in jsp and creating the project in shopping cart but ihave facing the problem while inserting the data in database. iam using the MsAccess
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
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
Jsp problem
Jsp problem  Hello friends.I want to share my jsp problem.I want to show all of my database(mysql) tables except two(user,manufacturer) in a jsp page.plssss help me
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want... name also is given by the user.My database is in mysql.Plsssss help me... Thanks..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want... name also is given by the user.My database is in mysql.Plsssss help me... Thanks..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want... name also is given by the user.My database is in mysql.Plsssss help me... Thanks..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
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
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should i do?? when the image retrieve from the database i want to set its size to how
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should i do?? when the image retrieve from the database i want to set its size to how
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text field........at that time action is perform and data is retriev from data base and get assign to other field on that form........ when data is assign to other
JSP Problem - JSP-Servlet
JSP Problem  Hi, I have problem,this is my senario I have one jsp,this jsp having the 3 fields.let me take 3fields userName,emailAddress... please do the needful   hi friend, form Insert into database
jsp problem
jsp problem  Hello Friends, I want to show one page for 5 seconds and after that i want to redirect the page to another URL
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 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
jsp problem
jsp problem  Hi every one plz give me answer for below question ASAP I created one JSP(used pre defined javascript in jsp to get rtf format in browser) which creats RTF Format in browser to enter data. MY question is after i
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
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 jsp programming - JSP-Servlet
problem in jsp programming  Write a JSP program which displays a webpage containing arrival of new items within a particular month in the different... in solving the problem : Connection with mysql database
jsp database
jsp database   I want to retrive value in my jsp page but i dont want show my database query in my jsp page. is there any other method to show value in my jsp page using java class
jsp code problem - JSP-Servlet
jsp code problem  Hi, I have employee details form in jsp. After validate all the fields, it will update the database, then move to next form. I have a problem with open the next form. plz, help me. thanks,  Hi
jsp problem - JSP-Servlet
jsp problem  hi, i am working on a project of developing a shopping cart for online book store.can it be done using jsp?if yes, can u please help me doing so?  Hi Friend, Please visit the following link: http
problem in programming - JSP-Servlet
problem in programming  Hi! I am new with jsp. I am facing a problem in programming to calculate the time interval between login time and logout time of user
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
jsp image problem - JSP-Servlet
jsp image problem  hi everyone, How to display multiple images from mysql database to jsp page. please help me
 

 

 

DMCA.com