Showing posts with label j2ee. Show all posts
Showing posts with label j2ee. Show all posts

Wednesday, June 26, 2019

JDBC - Java Database Connectivity.

 

   JDBC - Java Database Connectivity.

    Examples Included:

  1. Create a Database connection.     
  2. Fetch Data from Database table in your Java class.   
  3. Insert Data from Java Code into Database Table 

Git Location:
https://github.com/studyskymate/WebProject/tree/master/src/com/studyskymate/dinesh/java/login

      Note: Presentation download Link at the end of this page.


























 Example:

LoginJDBC.java

package com.studyskymate.dinesh.java.login;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoginJDBC {

    public static void main(String[] args)  {
   
    try {
       
//Registering the Driver
Class.forName("oracle.jdbc.driver.OracleDriver");

//Creating connection 
Connection con=
DriverManager.getConnection("jdbc:oracle:thin:@CEIT-SRV1.fnu.local:1521/orcl.fnu.local","hr","hr");

//Creating Statement 
Statement statement=con.createStatement();

//Execute Query
ResultSet rs =statement.executeQuery("select * from Employee");
   

    while(rs.next()) {
 
          System.out.println( 
          rs.getInt(1)+"                                        "+rs.getString(2));     
    }

   //Closing the connection
   con.close();

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    }

}



Check the Database for connection






Check the table to Query:

For Example, I want to query on Employee Table




 You need ojdbc.jar to be linked in your project to have a connection to the database.

Download the jar from below location and add in the library path of your project


http://www.java2s.com/Code/Jar/o/Downloadojdbc14jar.htm





 Run your Java Class to check the connection.




 Check the Result:

Below data is displayed as transferred from Table:










 Code for Insert into Employee Table:




InsertDataEx.java

package com.studyskymate.dinesh.java.login;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class InsertDataEx {

    public static void main(String[] args) {

try {
                Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con=DriverManager.getConnection("jdbc:oracle:thin:@CEIT-SRV-1.fnu.local:1521/orcl.fnu.local","hr","hr");
           

Statement statement=con.createStatement();
           
             
int result= statement.executeUpdate("INSERT INTO EMPLOYEE VALUES ('506','Dinesh')");
             
             
System.out.println("result: "+result);
           
           
} catch (ClassNotFoundException e) {
               
e.printStackTrace();
           
} catch (SQLException e) {
               
e.printStackTrace();
           
}
           
}
   
}











Presentation:










Tuesday, June 25, 2019

JSP Implicit Objects Presentation

JSP Implicit Objects Presentation

https://github.com/studyskymate/J2EEDemos/tree/master/WebContent/jspDemos



Question: Explain include Directive and include Action of JSP. Answer:   This is a very popular interview question on JSP, which has been asked from a long time and still asked in the various interview. This question is good to test some fundamental concept like translation of JSP and difference between translation time and run time kind of concept. Syntax for include Directive is : <%@ include file="fileName" %> which means we are including some file to our JSP Page when we use include directive contents of included file will be added to calling JSP page at translation time means when the calling JSP is converted to servlet ,all the contents are added to that page one important thing is that any JSP page is compiled if we make any changes to that particular page but if we have changed the included file or JSP page the main calling JSP page will not execute again so the output will not be according to our expectation, this one is the main disadvantage of using the include directive that why it is mostly use to add static  resources, like Header and footer .  Syntax for include action is  <jsp:include page=”relativeURL” />  It is a runtime procedure means the result of the JSP page which is mentioned in relative URL is appended to calling JSP at runtime on their response object at the location where we have used this tag. So any changes made to included page is being effected every time, this is the main advantage of this action but only relative URL we can use here, because request and response object is passed between calling JSP and included JSP.

JSP Implicit Objects Presentation



JSP Introduction presentation

JSP Introduction presentation


JSP Introduction


A JSP page is a text document that contains two types of text: static data, which can be expressed in any text-based format (such as HTMLSVGWML, and XML), and JSP elements, which construct dynamic content.

The recommended file extension for the source file of a JSP page is .jsp. The page can be composed of a top file that includes other files that contain either a complete JSP page or a fragment of a JSP page. The recommended extension for the source file of a fragment of a JSP page is . jspf.


A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role of a user interface for a Java web application. Web developers write JSPs as text files that combine HTML or XHTML code, XML elements, and embedded JSP actions and commands.

JSP Introduction presentation





Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > ...

Followers

Search This Blog

Popular Posts