How to connect with database

How to connect with database

jdbc connection

View Answers

May 21, 2013 at 8:18 PM

<%-- 
    view jsp
--%>

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    <center> <h1>View Your Location</h1>
        <form action="view" method="POST">
            <b> Enter Your Ignite Id:</b><input type="text" name="id" placeholder="IgniteId"><br><br>
            <input type="submit" value="SUBMIT" name="submit"><br><br><br>
            <table border="2">

                <th>Name</th>
                <th>home</th>
                <th>Location</th>
                <%
                    try {

                        ResultSet rs = (ResultSet) request.getAttribute("data");
                        while (rs.next()) {
                %>                                              
                <tr>
                    <td><input type="text" value="<%=rs.getString("name")%>"</td>
                    <td><input type="text" value="<%=rs.getString("home")%>"</td>
                    <td><input type="text" value="<%=rs.getString("location")%>"</td>
                </tr>
                <%                        }
                    } catch (Exception e) {
                    }
                %>

            </table>

        </form> </center> </body>
</html>

<%-- 
    view serverlet
--%>

PrintWriter out = response.getWriter();
        String Id = request.getParameter("id");

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/location", "root", "root");
            String id=request.getParameter("id");
        String query = "select * from posting where ignite_id='"+id+"'";
        Statement s = null;
            s = (Statement) con.createStatement();
            ResultSet rs = null;
             rs = s.executeQuery(query);
              request.setAttribute("data", rs);
        RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
        rd.forward(request, response);              

      } catch (Exception e) {
            out.print(e.toString());
        } finally {

            out.close();

        }
    }
<%-- 
    submit jsp
--%>
<center>  <form action="hit" method="POST">
            <fieldset>

                <b> iGnite Id:</b><input type="text" name="id" placeholder="Ignite Id"><br><br>
                <b>Your Name:</b><input type="text" name="name" placeholder="Name"><br><br>
               <b> Home Town:</b><input type="text" name="home" placeholder="Home"><br><br>
                <b>Location:</b><input type="text" name="location" placeholder="Location"><br><br>
                <b>Gender</b><input type="radio" name="sex" value="male">Male
                            <input type="radio" name="sex" value="female">Female<br><br>

                <b>Choice</b><input type="checkbox" name="choice" value="Kolkata">Kolkata
                            <input type="checkbox" name="choice" value="Chennai">Chennai
                            <input type="checkbox" name="choice" value="Mumbai">Mumbai
                            <input type="checkbox" name="choice" value="Delhi">Delhi<br>
                            <input type="submit" name="submit" value="Submit">

            </fieldset>
            <center><a href="view.jsp"><h1>VIEW</h1></a></center>



        </form></center>

<%-- 
    submit serverlet
--%>
PrintWriter out=response.getWriter();
        String Id=request.getParameter("id");
        String Name=request.getParameter("name");
        String Home=request.getParameter("home");
        String Location=request.getParameter("location");
        String Gender=request.getParameter("sex");
        String Choice=request.getParameter("choice");

        try{
         Class.forName("com.mysql.jdbc.Driver");
         Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/location", "root", "root");
        String sql="INSERT INTO posting (ignite_id,name,home,location,gender,choice) VALUES('"+Id+"','"+Name+"','"+Home+"','"+Location+"','"+Gender+"','"+Choice+"')";
      PreparedStatement ps=(PreparedStatement) con.prepareStatement(sql);
        ps.executeUpdate();
        ps.close();
        con.close();



        }
        catch(Exception e)
        {
            out.print(e.toString());
        }
        finally{
            out.print("Submit Successfully");
        out.close();

        }
    }









Related Tutorials/Questions & Answers:
How to connect with database
How to connect with database  jdbc connection
how to connect program to database
how to connect program to database  Sir i want ur help in my program. I want to save the data in the database. When i'll click on save button the entered data must be save in the database. I want an action performed method
Advertisements
Connect to the database
Connect to the database  how to connect to the database in the iphone
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
how to connect to database in php using mysql
how to connect to database in php using mysql  how to connect to database in php using mysql
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
How to connect to the database to my application if my database is made up in oracle
How to connect to the database to my application if my database is made up in oracle   How to connect to the database to my application if my database is made up in oracle
what is ment by jdbc and how to connect with database?
what is ment by jdbc and how to connect with database?  i want answer for this question
connect a web page to a database
connect a web page to a database  how to connect a web page to a database
How To Connect MS ACCESS 2003 Database in C Program with Graphics.
How To Connect MS ACCESS 2003 Database in C Program with Graphics.  How To Connect MS ACCESS 2003 Database in C Program with Graphics
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?  how to connect jsp with sql database by netbeans in a login page
TO connect multiple database
TO connect multiple database  How to connect several database from a single application in java depending upon the user input it will connect to that database
how to connect to MS access database in JSP?
how to connect to MS access database in JSP?  how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before it? Please tell what needs to be done after creating a table with an example
How to connect to database to my application if the database is made up in oracle
How to connect to database to my application if the database is made up in oracle  How to connect to database to my application if the database...) Connect to database:***ADS_TO_REPLACE_3 a) If you are using oracle oci driver
connect database with javascript
connect database with javascript  can you please tell me how to connect database with javascript code. [email protected] this is my mail id thanks in advance
connect to the database from JSP
connect to the database from JSP  How do you connect to the database from JSP?   A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets
Connect database in Access to Netbean?
Connect database in Access to Netbean?  how to connect database in micrsoft access to Netbean?i know it can be connected by using JDBC-ODBC bridge, can i know the steps in connecting the database? Is there any source code
How can I connect my database to my application ?
How can I connect my database to my application ?  How can I connect my database to my application?   Hi, You can use JDBC API to connect... code to connect to database: import java.sql.*; public class ConnetToDatabase
how to connect the database using hibernet through servlet/jsp through form
how to connect the database using hibernet through servlet/jsp through form  plz give me the reply   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/jsf/myfacesspring
How to connect to MySql Database from Servlet?
; font-weight: bold; } How to connect to MySql Database from Servlet... will show you how to connect to MySQL database and perform select operation. You will learn the JDBC steps necessary to connect to the MySQL Database and execute
cannot connect to database - JDBC
cannot connect to database  Iam using eclipse in my system ,when connecting the database mysql version 5.0 to the eclipse iam getting an error as ""Creating connection to mysql has encountered a problem.Could not connect to mysql
How to connect
How to connect  how to connect to a remote host using jsp? We need to update files to the database of the application on the local machine from the updated database on our webpage
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code.... try { Driver d=(Driver)Class.forName
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt.*; import java.sql.*; import javax.swing.*; import java.awt.event.*; class
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt.*; import java.sql.*; import javax.swing.*; import java.awt.event.*; class
Using Network Address To Connect to a Database
.style1 { text-align: center; } How To Use Network Address To Connect To The Database If a database being connecte over a network then you need to get... to connect a MySql database with your application over a network then you must load
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code. try { Driver d=(Driver)Class.forName
connect with Database - SQL
connect with Database  Hi, when ever i m trying to connect with 10g ..i m getting error .. Failed to get a connection org.jboss.util.NestedSQLException: Could not create connection; - nested throwable
How to connect to MySQL in JSP?
How to connect to MySQL in JSP?  How to connect to MySQL in JSP..., You can use the Java JDBC code to connect to MySQL database in JSP page. Check the tutorial: Connect JSP with mysql Thanks
connect database without specifying dsn name in java
connect database without specifying dsn name in java  How can i connect the database with my application without specifying the dsn name by using jdbc & odbc..... i have saw this code on the web-site try
how to connect webcam in html
how to connect webcam in html  how to connect webcam in html.emphasized text
How to connect mysql with jsp
How to connect mysql with jsp  how to connect jsp with mysql while using apache tomcat
How to connect to MySQL from command prompt?
learned How to connect to MySQL database from command prompt. Check all...How to connect to MySQL from command prompt? This video tutorial walks you... tutorial of: "How to connect to MySQL from command prompt?"ADS
pls provide steps to connect mysql database in flex - XML
pls provide steps to connect mysql database in flex  hi,i am new to flex and doing project. i have doubt in how to connect MYSQL database in flex .pls provide the steps . i would be really thankful 2 u. i am loooking
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following... offer .   Hi friend, Code to connect to database in servlet... to a databse by a servlet.I used the example in "Inserting Data In Database
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following... offer .   Hi friend, Code to connect to database in servlet... to a databse by a servlet.I used the example in "Inserting Data In Database
use properties file to connect to the database in jsp..
use properties file to connect to the database in jsp..  How to use properties file to connect jsp code with database ..........   Here is a jsp code that connects to database using properties file. <%@page import
How to Connect J ComboBox with Databse - Java Beginners
How to Connect J ComboBox with Databse  How to Connect J ComboBox with Databse  Hi Friend, Do you want to get JComboBox values from database?Please clarify this. Thanks
how i connect two page
how i connect two page  strong textlink text
how to connect jdbc
how to connect jdbc  package com.tcs.ilp.Try.Controller; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import
how to connect mysql with JDBC - JDBC
how to connect mysql with JDBC  I have created three tables in the database MYsql, i have to connect them now using JDBC, can u please suggest me...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC
How to connect on screen keyboard to system.
How to connect on screen keyboard to system.  How to connect on screen keyboard to system.I made on screen keyboard in java(swing).Now i want connect to system means when i pressed any button then it type on notepad or any
How to connect on screen keyboard to system.
How to connect on screen keyboard to system.  How to connect on screen keyboard to system.I made on screen keyboard in java(swing).Now i want connect to system means when i pressed any button then it type on notepad or any
how to connect mySql drivers into eclipse(configuration)?
how to connect mySql drivers into eclipse(configuration)?  how to connect mySql drivers into eclipse(configuration)? I need the configuration... i have to install anything to create a database and tables
Using javabeans to connect mySQL database on a jsp page - JSP-Interview Questions
Using javabeans to connect mySQL database on a jsp page  Hi, Am doing my project and I don't know how to connect a jsp page to a mySQl database...; Connecting a JSP page to MYSQL Database using JavaBean File Name: beancode.java
pls provide steps to connect mysql database in flex - XML
pls provide steps to connect mysql database in flex  hi, pls provide steps to connect mysql database in flex.pls i am trying from last week still it was not connected .pls provide the step by step procedure.i am looking
Connect JSP with mysql
how to connect to MySQL database from your JSP code. First, you need to create database and then write jsp code to connect jsp to database.ADS_TO_REPLACE_1...) Here is the video tutorial of "How to connect to MySQL Database from JSP
how to connect SQL Server 2005 using php
how to connect SQL Server 2005 using php  i need to connect SQL Server 2005 using php. how can i connect . how to use mssql_connect function

Ads