Home Answers Viewqa JSP-Servlet use properties file to connect to the database in jsp..

 
 


dhananjay dwivedi
use properties file to connect to the database in jsp..
2 Answer(s)      8 months ago
Posted in : JSP-Servlet

How to use properties file to connect jsp code with database ..........

View Answers

September 3, 2012 at 3:58 PM


Here is a jsp code that connects to database using properties file.

<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>

<%
        Properties prop = new Properties();

        prop.load(new FileInputStream("data.properties"));
        String user = prop.getProperty("username");
        String pass = prop.getProperty("password");
        String port = prop.getProperty("port");

        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:"
                + port + "/test", user, pass);
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery("Select * from data");
        while (rs.next()) {
            out.println(rs.getString(1) + " " + rs.getString(2)+"<br>");
        }

    %>

Here is a data.properties file.

username=root
password=root
port=3306

September 4, 2012 at 1:29 AM


Thank for giving your valuable response ...

We can also use as..

db.properties file

driver=sun.jdbc.odbc.JdbcOdbcDriver

connectionurl=jdbc:odbc:pro

username=PRS_ACC

password=prs

save the file.

check.jsp page
<%@page import="java.sql.*"%>

<%@page import="java.io.FileInputStream"%>

<%@page import="java.io.FileNotFoundException"%>

<%@page import="java.io.IOException"%>

<%@page import="java.util.Properties"%>//for use properties 

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

    <head>

         <title>JSP Page</title>

    </head>

    <body>

        <h1>welcome user</h1>


    <%
final Properties myresources = new Properties();

try {
    FileInputStream in = new FileInputStream(
            "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\CustomerInfoSystem\\WEB-INF\\classes\\ApplicationResources.properties");//path of the properties file

        try {

            myresources.load(in);

            }

        catch (Exception e) {

        e.printStackTrace();

        }
    } 

catch (Exception e) {

    e.printStackTrace();

}

try

   {

    RequestDispatcher rd=null;

    Connection con=null;

    ResultSet rs=null;

    String drvr=myresources.getProperty("driver");

    String url=myresources.getProperty("connectionurl");

String user_name=myresources.getProperty("username");

    String passw=myresources.getProperty("password");

Class.forName(drvr);//for driver
con=DriverManager.getConnection(url,user_name,passw);//for url and user name  and password.

    String name1=request.getParameter("user");

    String pass=request.getParameter("pass");

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

            //con=DriverManager.getConnection("jdbc:odbc:pro","PRS_ACC","prs");

    Statement st=con.createStatement();

    String sql="select name from user_profile where name='"+name1+"' and password='"+pass+"'" ;

    out.println("query:::"+sql);

    rs=st.executeQuery(sql);

    while(rs.next())
    {
          String aa=rs.getString(1);
          out.println(">>>>>>>"+aa);
          if(name1.equals(aa))
            {
             response.sendRedirect("Welcome.jsp");
             session.setAttribute("username", name1);
            }
    }
    rd=request.getRequestDispatcher("Login.jsp");
    rd.forward(request, response);
    st.close();
    con.close();    
    }
    catch(Exception e)
    {
           out.println(" error"+e);
     }
%>
    </body>
</html>

It must work...









Related Pages:
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
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... properties file JNDI_NAME=java:com/env/Oracle/jndi db.login= db.password
Properties file in Java
the properties file to store the configurable values like database connection string... Properties file in Java       In this section, you will know about the properties file
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
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following... tested HelloWorld sample code and it was ok,but the tutorials which use database... offer .   Hi friend, Code to connect to database in servlet
i can not connect to database in servlet - JSP-Servlet
i can not connect to database in servlet  Hi I am following... tested HelloWorld sample code and it was ok,but the tutorials which use database... offer .   Hi friend, Code to connect to database in servlet
connect jsp with tomcat - JSP-Servlet
connect jsp with tomcat  hello friends, i have severe problem in making connection between tomcat 6.0.18 and jsp pages.my system configuration... web.xml file.. or put your jsp prg folder in jsp-examples only, you can send
Connect JSP with mysql
; This query creates database 'usermaster' in Mysql. Connect JSP with mysql : Now in the following jsp code, you will see how to connect... Connect JSP with mysql   
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
common database jsp file for all the jsp files in the application
common database jsp file for all the jsp files in the application  hi, i have written jspcode to connect to mysqldatabase . i need the code to make use of this single jsp file while connecting to database rather than writing
Connect from database using JSP Bean file
Connect from database using JSP Bean file... to the MySQL database and then we have made the properties setter and getter... methods of this bean file we have to make entry for bean class in jsp file
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
applicationcontext.xml properties file
applicationcontext.xml properties file In this tutorial I will explain how you can use the properties defined in .properties file in your spring application... changing the properties file. Suppose you are developing an email sending
How to use an object properties in jsp page
How to use an object properties in jsp page  I have a arraylist of objects 'User' populated using struts 2 action class while loading that jsp page. In that JSP I have included another jsp using following tag: Here instead
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... Class.forName("oracle.jdbc.driver.OracleDriver"); 3) Connect to database
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
How to write .properties file from jsp
it in my jsp but Iam unble to modify/write the .properties file and Iam not getting... to implement/write .properties file from jsp. Regards, Venkatesh Gurram...How to write .properties file from jsp  Hi i new to java i stuck here
Java Properties File Example
Using Properties files Java Stets to use a properties files in Java. 1... an object of Properties class. 3. After that load the properties file into the program. 4. Finally get the text using the key of the properties file. An example
Mysql connect
Mysql connect  i can have a mysql database file and mysql-connector-net .but i have not mysql database. how to connect vb.net thsis database.(C:\Documents and Settings\Admin\My Documents\VB.NET\Stock delna\STC.sql ). plz help me
Connect to the database
Connect to the database  how to connect to the database in the iphone
database
links: Connect JSP with database Mysql Connect Java with database Mysql...database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover
database
links: Connect JSP with database Mysql Connect Java with database Mysql...database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover
database
links: Connect JSP with database Mysql Connect Java with database Mysql...database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover
how to connect jsp to mysql - Java Beginners
how to connect jsp to mysql  I m new in Mysql and JSP i m ceating.java file using bean file for connectivity but i m not able to connect jsp... me hw to conncet jsp with mysql this is connection file package connect
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
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
Loading properties from a XML file
Loading properties from a XML file       This Example shows you how to Load properties from a XML... parsers. Some of the methods used for loading properties from a XML file
Using Network Address To Connect to a Database
.style1 { text-align: center; } How To Use Network Address To Connect... to connect a MySql database with your application over a network then you must load... is "root" An example of using network address to connect to 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
Storing properties in XML file
Storing properties in XML file     ... in xml file:- File f=new File("2.xml"):-Creating File in which properties... file in which properties are stored by the program :- #File Created
java script unable to connect to oracle database and insert data
java script unable to connect to oracle database and insert data  ... is to insert data from jsp to oracle database 8, so i create a table in oracle... to run the jsp file from tomcat i get this error.. let me know what i am doing
Properties
in a file Use the Properties .store(OutputStream, String) method. It will write..."); To load Properties from a file Use the Properties .load(InputStream.... This is the class to use to implement persistent variables (values which are saved in a file
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
unable to connect to server - JSP-Servlet
, create a web application folder inside the webapps folder and put the jsp file...unable to connect to server  thank you for the program code for inserting and reteriving the image but i am unable to deploy these two programs
Connect JSP with mysql
you 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... database in my sql command prompt) 2. Connect JSP with mysql: 
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
write excel file into the oracle database
write excel file into the oracle database  dear sir, i need the jsp code that reads the excel file and stores it into the oracle database table..and also i need the code to connect oracle database? thank u in advance
Ant Custom Properties
Ant Custom Properties        Setting properties in the build file is the first method of providing custom properties with <property> element in an ant build file
connect a web page to a database
connect a web page to a database  how to connect a web page to a database
Connecting to MySQL database and retrieving and displaying data in JSP page
Connecting to MySQL database and retrieving and displaying data in JSP page...; This tutorial shows you how to connect to MySQL database and retrieve the data from the database. In this example we will use tomcat version 4.0.3 to run our
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 swings with jdbc... - Java Beginners
how to connect swings with jdbc...  Hi friends, Is it possible, to connect swings with data base like oracle....i want to store data into database... by using servlets and jsp but is it possible by using swings........ for data base
Using MYSQL Database with JSP & Servlets.
tables for our tutorial. To connect to a database "use <... to connect to mysqltutorial database.   mysql> use... to connect to the database from JSP page. Send you queries
struts2 properties file
struts2 properties file  How to set properties file in struts 2 ?   Struts 2 Format Examples Struts 2 Tutorial
Reference Class Properties
Reference Class Properties       This Example shows you how to use class properties... of VelocityContext Class. 3: Use put() method of Class VelocityContext 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.