how to display data from jsp file into database
this is a jsp file . look at the line with code-> Statement st=con.createStatement(); in the below example. the error is "cannot convert from java.sql.Statement to com.mysql.jdbc.Statement
please help me with it. thanks
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
Insert title here
<%
String t=request.getParameter("title");
String n=request.getParameter("name");
String cn=request.getParameter("cname");
String pos=request.getParameter("pos");
String req=request.getParameter("req");
String eid=request.getParameter("emailId");
String ph1=request.getParameter("phone1");
String ph2=request.getParameter("phone2");
Connection con = null;
Statement st=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/commondb", "root", "root123");
st=con.createStatement();
int i=st.executeUpdate("insert into contactinfo(title,name,cname,pos,req,emailId,phone1,phone2) values('"+t+"','"+n+"','"+cn+"','"+pos+"','"+req+"','"+eid+"',"+ph1+","+ph2+")");
out.println("Data is successfully inserted!");
//System.out.println("rows affected by insert "+st.executeUpdate(i));
}
catch(Exception e){
e.printStackTrace();
}
%>
View Answers
August 17, 2011 at 5:19 PM
1)form.jsp:
<html>
<form method="post" action="insertdata.jsp">
<table>
<tr><td>Username:</td><td><input type="text" name="uname"></td></tr>
<tr><td>First Name:</td><td><input type="text" name="fname"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lname"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address"></td></tr>
<tr><td>Contact No:</td><td><input type="text" name="contact"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
2)insertdata.jsp:
<%@page import="java.sql.*,java.util.*"%>
<%
String uname=request.getParameter("uname");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String pass=request.getParameter("pass");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("email");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into login(username,password,firstname,lastname,address,contactNo,email) values('"+uname+"','"+pass+"','"+fname+"','"+lname+"','"+address+"',"+contact+",'"+email+"')");
out.println("Data is successfully inserted into database.");
con.close();
}
catch(Exception e){
System.out.println(e);
}
%>
August 17, 2011 at 5:25 PM
still the problem persists
August 18, 2011 at 10:46 AM
Please specify your problem....
August 18, 2011 at 11:15 AM
solved it . some problem with import..
Related Tutorials/Questions & Answers:
how to display data from jsp file into databasehow to
display data from jsp file into database this is a
jsp file...+",'"+email+"')");
out.println("
Data is successfully inserted into
database...(); in the below example. the error is "cannot convert
from java.sql.Statement
Advertisements
Display Data from Database in JSP, to show
data from the
database
click on the link that calls another .
jsp file named...;
<html>
<head>
<title>
display data from...;To
display all the
data from the table click here...</h2></TD>
data are not display in JSP from database - JSP-Servletdata are not
display in
JSP from database
i want to finding some
data through a SQL query
from SQL server
database to a
JSP page based on some... of this
jsp page. like..
School Result
and three request parameters 'class', '
from How to display data from database in a TableViewHow to
display data from database in a TableView I need to populate a TableView (JavaFx) with
database items. I designed the TableView in JavaFx... at this.
The classes:
This is the Class that creates the
database data object:
import
Display Data from Database in JSP Display Data from Database
in
JSP
...
from the
database
click on the link that calls another
jsp file named... and execute query to
display data from the
specified table.
Before
how to display values from database into table using jsphow to
display values
from database into table using jsp I want to
display values
from database into table based on condition in query,
how... the values
from database based on the bookname or authorname entered must be
display display date to jsp from database display date to
jsp from database display date to
jsp from database to calender
if the start date and end date is available than calender date... not available in
database field than show in green color and clickable.
NOTE :- Date
How to show data from database in textbox in jsp How to show
data from database in textbox in
jsp How to show
data from database in textbox in
jsp
Here is an example that retrieve the particular record
from the
database and
display it in textbox using
JSP.
<
How to display data in jsp from dao using java beans?How to
display data in
jsp from dao using java beans? Hi
I need to
display data in
jsp pulling
from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
how to get data from database into dropdownlist in jsphow to get
data from database into dropdownlist in jsp Can anybody tell me what is the problem in this code as i am not able to fetch the
data from... tutorial go through the link
JSP Get
Data Into Dropdown list
From Database
jfreechart display from access database data.jfreechart
display from access
database data. I have made a
database... to retrieve the
data from the access
database using prepared statement and then
display... is to be done in a servlet..
Note that it is a access made
database.
How can I
How we delete a data of database from front end jsp page How we delete a
data of
database from front end
jsp page I make a website and featch a
data from data base and now i want that a delete button put... deleted
from jsp page as well as
from database.I used mysql and
jsp. Please help me
How to Retrieve data from database in jspHow to Retrieve
data from database in
jsp
In this section we will discuss about
how to fetch
data from database table.
We will give a simple example which...
Here is the video tutorial of "
How to retrieve
data from database how to display a table from database using servlethow to
display a table
from database using servlet
how to
display... the following link:ADS_TO_REPLACE_1
http://roseindia.net/
jsp/servlet-
jsp-
data... the following link:
http://roseindia.net/
jsp/servlet-
jsp-
data-list.shtml
ThanksADS
how to display records from databasehow to
display records
from database I want to
display records
from database in tables, the
database is having 2000 records and i want to
display 20 records at a time and to use next and previous link buttons to show
How to display the data column on jspHow to
display the
data column on jsp My requirements:
Display total...;
</form>
It
display the
data of last
database server...
..
in table of each
database having two columns: description, error. but
data How to get data from Oracle database using JSPHow to get
data from Oracle
database using JSP hello i have a simple problem in
jsp in the sense to get
data from the
database like oracle . I have...
data from the
database like oracle), I have created one
jsp program like