connect to the database from JSP

Ads

 
 

Share on Google+Share on Google+

Vijay Kumar
connect to the database from JSP
3 Answer(s)      7 years ago
Posted in : JSP-Interview Questions

How do you connect to the database from JSP?

Ads
View Answers

October 30, 2010 at 12:56 PM


A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets.



April 5, 2011 at 11:24 PM


<%@ page import="java.sql.*" %> <%! String Uname_Text; String Passwd_Text;%> <% Uname_Text=request.getParameter("Uname"); Passwd_Text=request.getParameter("Passwd"); request.setAttribute("Uname",Uname_Text);

try{

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}

    catch(Exception e){ out.println("Driver Detection Failed.");  }

    try{
    Connection conn;
    Statement stm;
    String db = "jdbc:odbc:test";


     conn = DriverManager.getConnection(db,"","");
    System.out.println("****Connected to database***");

stm = conn.createStatement();

    if(Uname_Text=="" || Passwd_Text=="")
    {

        response.sendRedirect("http://localhost:4040/Myjsp/Login_Fail.jsp");
        out.println("Username is empty.");
    }

ResultSet rs = stm.executeQuery("select * from Table1 where UnameTable='"+ UnameText +"' AND PasswdTable='"+PasswdText+"'"); while(rs.next()) {

            out.println(rs.getInt(1) );



            out.println(rs.getString(2) );

            out.println(rs.getString(3) );
            out.println(rs.getString(4) );
            out.println(rs.getString(5) );
            out.println(rs.getString(6) );
               out.println(rs.getString(7)); 

            out.println();
            out.println("");


        }

conn.close();

    }

catch(SQLException e) {

    }

%>



April 5, 2011 at 11:28 PM


this shows the connection as well as insert command....for update use executeUpdate("upadate command here");


Ads









Related Tutorials/Questions & Answers:
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
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... DSN will get created. 6) Restart your server and run your jsp code. Here is your
Advertisements
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
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
Connect to the database
Connect to the database  how to connect to the database in the iphone
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
Connecting to Database from a hyperlink in JSP - JSP-Servlet
Connecting to Database from a hyperlink in JSP  How can I connect to database by clicking on a hyperlink in a JSP Page.Can you please give me sample... which is connect to database using jdbc database
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. 1. Create... tutorial of "How to connect to MySQL Database from JSP?": 2
line chart from database in jsp
line chart from database in jsp  how can i create line chart from database in jsp code
Connect from database using JSP Bean file
Connect from database using JSP Bean file...; is doing the loading of bean file from the classes. <jsp:useBean id...; Java Beans are reusable components. It is used to separate Business logic from
Update Database from jsp
Update Database from jsp   I want to update my oracle database column from a text box ,so whenever I input some text value in the text box and click UPDATE button the database field should be updated . I have a drop down menu
How to access the database from JSP?
How to access the database from JSP?  Hi, What is the process of accessing the database from JSP page? Thanks   Hi, In the JSP program... database from JSP which explains you how to access the database by embedding
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
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 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: http://www.roseindia.net/jsf/myfacesspring/loginRegistration.shtml Hope
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
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data..
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data.... If I use it also, unable to connect to backend oracle database. Let me... max("+pkid+") from "+tableName); if(rs.next
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
search functionality using jsp from database
search functionality using jsp from database  search functionality using jsp from database
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
Display Data from Database in JSP
Display Data from Database in JSP    This is detailed java program to connect java application with mysql database.... This is first jsp page that has a link 'show data from table', user can show
data are not display in JSP from database - JSP-Servlet
data 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
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP... to retrieve image from mysql database in JSP? Thanks   Hi, You can write... images from Database in JSP. Thanks
Loading a jsp page (with record from database) from another jsp page
Loading a jsp page (with record from database) from another jsp page  Suppose I have two jsp pages Search.jsp and Getdata.jsp. There are two fields... with records from database(against Serial no and year).That is, as soon
How to retrieve blob image from database in JSP?
How to retrieve blob image from database in JSP?  Hello, JSP is used... the blog image from database. How to retrieve blob image from database in JSP?   Hi, Please check the tutorial Retrieve image from database using
How to store and retrieve image from database in JSP?
How to store and retrieve image from database in JSP?  Hi, In one... and retrieve image from database in JSP? Thanks   HI, You can use... the image. Check this example: Retrieve image from database using Servlet. Thanks
connect a web page to a database
connect a web page to a database  how to connect a web page to a database

Ads

 
Advertisement null

Ads