database connectivity
i m trying to connect this servlet with database but i m not able to
Code is ot giving any error and there is no update in database plsss somebody can help
code is here
package newpackage;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "exam", urlPatterns = {"/exam"})
public class exam extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String id = request.getParameter("id");
out.print("id"+ id);
String name=request.getParameter("name");
try{
out.print("statrted");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.print("loaded");
con= DriverManager.getConnection("jdbc:odbc//localhost:3306/example","root","root");
out.print("connected");
ps= con.prepareStatement("insert into new values(?,?)");
rs=ps.executeQuery();
rs.first();
{ ps.setString(1,id);
ps.setString(2,name);
ps.executeUpdate();
}
out.print("executed");
con.close();
}
catch (Exception e)
{
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
View Answers
March 20, 2012 at 4:18 PM
March 20, 2012 at 4:18 PM
Connect Servlet with database and insert data
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class InsertServlet extends HttpServlet {
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String name=req.getParameter("name");
String pass=req.getParameter("pass");
String address=req.getParameter("address");
int no=Integer.parseInt(req.getParameter("no"));
String gender=req.getParameter("gender");
String country=req.getParameter("country");
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 mail(name,password,address,telno,gender,country) values('"+name+"','"+pass+"','"+address+"',"+no+",'"+gender+"','"+country+"')");
out.println("Data is inserted successfully");
con.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
Ads
Related Tutorials/Questions & Answers:
database connectivity
database connectivity how to create
database connectivity between HTML and sql server2005
Database Connectivity
Database Connectivity I tried to establish
database connection with sqlserver2008 through GlassFish server.
When I set the path of sqljdbc.jar(E:\Glass Fish\glassfish-v2ur1\javadb\lib\sqljdbc.jar) it shows me error
Advertisements
database connectivity
database connectivity i have written class.forName and getconnection in one method which returns connection string object under particular class and in someother class i want to call that for statement object
database connectivity
database connectivity i m trying to connect this servlet with
database but i m not able to
Code is ot giving any error and there is no update in
database plsss somebody can help
code is here
package newpackage;
import
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 Connectivity Withe Oracle
Database Connectivity Withe Oracle Develop a program to perform the
database driven operation like insert, Delete,
Update and select. To perform the above operations create one table named
Employee.
Field Name Field Type
EmpId
Access 2007 database connectivity
Access 2007
database connectivity i design an application form... source and destination. pls tell me the code of
connectivity with access 2007
database using JComboBox.thanks
Oracle Database connectivity probem
Oracle
Database connectivity probem hi
Below is the code of oracle
database connectivity, when i compile it, it will show the error: oracle.jdbc.driver.OracleDriver I am using netbeans 6.5 and tomcat 6.0 and jdk 1.6 i have
database connectivity using mysql
database connectivity using mysql java file: eg1.java
package eg;
import java.sql.*;
public class eg1
{
public static void main(String arg[]) throws SQLException
{
try
{
String connectionURL = "jdbc:mysql
About DataBase Connectivity
About
DataBase Connectivity I want a simple code in which is like two tier application
one system have data base and application is running on other system.
Pls inform the way hoe to connect both system
{I want to run
About DataBase Connectivity
About
DataBase Connectivity I want a simple code in which is like two tier application
one system have data base and application is running on other system.
Pls inform the way hoe to connect both system
{I want to run
Java database connectivity
Java
database connectivity Hi sir
I need a code to create an application where user enter name in text box and that should be stored in
database.
Plz help me out its very urgent.
import java.sql.*;
import java.awt.
database connectivity using jsp code
database connectivity using jsp code i have two tables employee and adduser
insert into adduser(Emp_Id,Ename,Designation,Password,ReTypePassword)values('6867678po',(select Ename from employee),(select Designation from employee
online database connectivity issue from JSP page .
online
database connectivity issue from JSP page . Hi;
Everything working fine in localhost , but facing a simple problem in
connectivity with
database from my web site.
In my local host-- when I am typing
online database connectivity issue from JSP page .
online
database connectivity issue from JSP page . Hi;
Everything working fine in localhost , but facing a simple problem in
connectivity with
database from my web site. In my local host-- when I am typing following code
online database connectivity issue from JSP page .
online
database connectivity issue from JSP page . Hi;
Everything working fine in localhost , but facing a simple problem in
connectivity with
database from my web site. In my local host-- when I am typing following code
connectivity
connectivity fetching the value of any form into the
database
Database Connectivity Example In Java
Database Connectivity Example In Java
In this section we will read about how to establish a connection between Java
program and
database.
To establish a connection between the
database and Java program Java provides
the JDBC API
Servlet Database Connectivity Example
Servlet
Database Connectivity Example
We are going to describe how to connect to the
database in servlet.We have been provide some classes and API with which we will make use of the
database connection.
Database plays an important role
database connectivity in jsp form
database connectivity in jsp form
We are going to create jsp registration form
database. We first create simple registration form.
All data will be stored in he
database. We use method getParameter()
that return the value
Database
Database Can i get a code for
database connectivity
Myeclipse 3.3 to MySql manager 2005
connectivity with php
connectivity with php i have make one html form and doing
connectivity with php
database but when i click on submit button on html form display all coding in php form about
connectivity instead of adding data, i used in html
connectivity with access
connectivity with access how to connect with data base with access...; Is this Access
database or excel sheet. Do you want to display the values...;Is this Access
database or excel sheet. Do you want to display the values in Textarea
connectivity with mysql
connectivity with mysql if this code of roseindia doesnt work,then what to do..cant connect with my sql
http://www.roseindia.net/tutorial/php...-
database-connection.shtml
JDBC CONNECTIVITY
JDBC CONNECTIVITY How do i connect my
database to java. I have the connector file and i place it in lib of jdk folder and installed the jdbc driver... file in environment variable.
Java Mysql
connectivity
Other JDBC