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..
Ads
Related Tutorials/Questions & Answers:
how to display data from jsp file into database
how 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>
How to display data from database in a TableView
How 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
how to display values from database into table using jsp
how 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 Data from Database in JSP
Display Data from Database
in
JSP
 ... and execute query to
display data from the
specified table.
Before....
This is first
jsp page that has a link 'show
data from
table', user can show
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 get data from database into dropdownlist in jsp
how 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
 
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 Retrieve data from database in jsp
is the video tutorial of "
How to retrieve
data from database and
Display in
JSP Page...
How 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
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