Share on Google+Share on Google+

Vijay Kumar
connect to the database from JSP
3 Answer(s)      6 years and 5 months 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");










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
Connect to the database
Connect to the database  how to connect to the database in the iphone
Advertisements
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
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. <[email protected] import
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
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
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
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
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
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
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
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
connect a web page to a database
connect a web page to a database  how to connect a web page to a database
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
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
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...How to connect to MySQL in JSP?  How to connect to MySQL in JSP
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
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
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
line chart from database in jsp
line chart from database in jsp  how can i create line chart from database in jsp code
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
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
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
How to connect with database
How to connect with database  jdbc connection
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
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
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 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
Tutorials   
Java Spring Hibernate Struts Training why do not required application restart after jsp changes? How to use contentType Attribute in JSP? How to connect to MySQL in JSP? JSP Comment Types with example How to use ajax in jsp? How to access the database from JSP? how to show image as a link which path coming from database jsp netbeans javascript Logos on mail inbox. I want to update the multiple values of database depending on checkbox..? Please help me out.. jsp 18/04/2013 JSTL how to access element added via javascript dynamically using jsp code Electronic spreadsheets are useful in situation An E-mail protocol for storage JSP JSP JSP jsp servlets Exception: com.mysql.jdbc.Driver display data from database on selecting option of dropdownlist display data from database on selecting option of dropdownlist display data from database on selecting option of dropdownlist display data from database on selecting option of dropdownlist Jsp Query run command prompt from jsp program question for c++ please help me how to set up Netbeans for JSP 3 dropdown list from the database using JSP autocompletion in textfield fetching from database in jsp openning the pdf or doc file in same jsp EXT JS tt need coding JSp session time out how to display values from database into table using jsp how to set the class path variable in tomcat ? need help please online examination system mini project problem in writing coding. Please help me. How to read the body content of custom tag? need help...................please please help me jsp coding please. help me image upload Assertions I want to store the value of local variable into Global variable how to create customise shortcut keys in jsp?

Ads

 
Advertisement null

Ads