Sunday 25 September 2011

Read XML file using JSP.

name.xml
<?xml version="1.0" encoding="utf-8"?>

<xmldata>
    <student>
        <RegistrationNo>1</RegistrationNo>
        <StudentID>1110708058</StudentID>
        <Name>Jatin Kansagara</Name>
        <FName>Mr.Jatin</FName>
    </student>
    <student>
        <RegistrationNo>2</RegistrationNo>
        <StudentID>1110708048</StudentID>
        <Name>Ashvin</Name>
        <FName>Mr. Ashvin</FName>
    </student>
</xmldata>


ReadXML.jsp

<%@ page contentType="text/html; charset=utf-8" language="java" import="javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" errorPage="" %>
<%
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();

Document doc = db.parse("name.xml");

NodeList RegistrationNo = doc.getElementsByTagName("RegistrationNo");
NodeList StudentId = doc.getElementsByTagName("StudentID");
NodeList Name = doc.getElementsByTagName("Name");
NodeList FName = doc.getElementsByTagName("FName");
%>

<html>
<head>
<title>Read Xml Data</title>
</head>

<body>
<table border="1">
<%
int i;
for(i=0;i<=RegistrationNo.getLength()-1;i++)
{
%>

<tr>
<td>

 <%= RegistrationNo.item(i).getFirstChild().getNodeValue()%>
</td>
<td>
    <%= StudentId.item(i).getFirstChild().getNodeValue()%>
</td>
<td>
    <%= Name.item(i).getFirstChild().getNodeValue()%>
</td>
<td>
    <%= FName.item(i).getFirstChild().getNodeValue()%>
</td>
</tr>
<%
}
%>
</table>
</body>
</html>

Learn more java tutorial and java blog visit : http://www.visionsdeveloper.com

Thursday 15 September 2011

What is Hibernate

Hibernate is popular open source object relational mapping tool for Java platform. It provides powerful, ultra-high performance object/relational persistence and query service for Java. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework.
Hibernate takes care of the mapping from Java classes to database tables and also provides data query and retrieval facilities. Hibernate significantly reduces development time in the software projects.
Hibernate is an open source object/relational mapping tool for Java. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework.
Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC.
Hibernates goal is to relieve the developer from 95 percent of common data persistence related programming tasks.
Hibernate is Free Software. The LGPL license is sufficiently flexible to allow the use of Hibernate in both open source and commercial projects (see the LicenseFAQ for details). Hibernate is available for download at http://www.hibernate.org/. This tutorial aims to provide insight into Hibernate version 3.0RC and its usage Some of the main features of hibernate are listed below and we have tried to explain some of them in detail later in this tutorial.
Transparent persistence without byte code processing
Transparent persistence
JavaBeans style properties are persisted
No build-time source or byte code generation / processing
Support for extensive subset of Java collections API
Collection instance management
Extensible type system
Constraint transparency
Automatic Dirty Checking
Detached object support
Object-oriented query language
Powerful object-oriented query language
Full support for polymorphic queries
New Criteria queries
Native SQL queries
Object / Relational mappings
Three different O/R mapping strategies
Multiple-objects to single-row mapping
Polymorphic associations
Bidirectional associations
Association filtering
Collections of basic types
Indexed collections
Composite Collection Elements
Lifecycle objects
Automatic primary key generation
Multiple synthetic key generation strategies
Support for application assigned identifiers
Support for composite keys
Object/Relational mapping definition
XML mapping documents
Human-readable format
XDoclet support
HDLCA (Hibernate Dual-Layer Cache Architecture)
Thread safeness
Non-blocking data access
Session level cache
Optional second-level cache
Optional query cache
Works well with others
High performance
Lazy initialization
Outer join fetching
Batch fetching
Support for optimistic locking with versioning/timestamping
Highly scalable architecture
High performance
No “special” database tables
SQL generated at system initialization time
(Optional) Internal connection pooling and PreparedStatement caching
J2EE integration
JMX support
Integration with J2EE architecture (optional)
New JCA support

Printing using Java Script.

Print a page using Java Script:

<html>
<head>
<script>
function printpage(){
window.print();
}
</script>
</head>
<body>
<h>This is Printing Page</h>
<button onClick = "printpage()">Print</button>
</body>
</html>

Tuesday 13 September 2011

My sql Connection with Java

 import java.sql.*;

public class MysqlConnect{
  public static void main(String[] args) {
    System.out.println("MySQL Connect Example.");
   
    try {
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/"; // Connection url for mysql
    String dbName = "test";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root";
    String password = "";
   
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url+dbName,userName,password);
      System.out.println("Connected to the database");
      conn.close();
      System.out.println("Disconnected from database");
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}

Run this program you need
mysql-connector-java-5.1.13-bin.jar

If you connect with oracle than Connection url is : "jdbc:oracle:thin:@localhost:1521:oracle"

"oracle" is a database

Saturday 10 September 2011

Important Site for Java Developer

http://www.javaalmanac.com/ - The online counterpart of the Java Developer's Almanac - highly recommended for quick code snippets, and if you like the site, buy the book.

http://www.onjava.com/ - O'Reilly's Java website. New articles weekly.

http://java.sun.com/ - The official Java developer website - new articles posted weekly.

http://www.developer.com/java - Java articles hosted by Gamelan.com

http://www.java.net/ - The Java community website hosted by Sun Microsystems.

http://www.builder.com/ - Cnet's Builder.com website - All tech articles, some Java-centric.

http://www.ibm.com/developerworks/java - IBM's Developerworks; the Java section.

http://www.javaworld.com/ - One of the originals. Weekly updates of Java articles.

http://www.devx.com/java - Java articles hosted at DevX.

http://www.fawcette.com/javapro - The JavaPro online magazine website.

http://www.sys-con.com/java - The Java Developers Journal online magazine website.

http://www.javadesktop.org/ - The desktop Java community hosted at Java.net.

http://www.theserverside.com/ - Often considered the resource for all discussion server-side Java specific.

http://www.jars.com/ - The Java review service. Covers frameworks and applications.

http://www.jguru.com/ - A great source for Q&A style interaction in the community.

http://www.javaranch.com/

http://www.ibiblio.org/javafaq/javafaq.html - The comp.lang.java FAQ - questions asked, answered, and categorized from the comp.lang.java newsgroup.

http://java.sun.com/docs/books/tutorial/ - The Official Java tutorial from Sun - very useful for almost any feature set.

http://www.javablogs.com/ - Blog aggregator for the most active Java-based blogs throughout the internet.

http://java.about.com/ - Java news and articles from About.com.

http://www.java2s.com/ - Java Example

http://www.roseindia.net/ - Java Example with explanation , Also provide tutorial for Frameworks : Hibernate, Struts, Spring etc.

http://www.servletworld.com/ - Java servlet tutorial, Jsp tutorial , Servlet example and J2ee Tutorial.

http://www.visionsdeveloper.com - Tutorial for Java, Struts2, Hibernate, Spring, Javascript, Ajax, Html etc, and All Blog.

List of Dialect use for hibernate

DB2 - org.hibernate.dialect.DB2Dialect
HypersonicSQL - org.hibernate.dialect.HSQLDialect
Informix
- org.hibernate.dialect.InformixDialect
Ingres - org.hibernate.dialect.IngresDialect
Interbase - org.hibernate.dialect.InterbaseDialect
Pointbase - org.hibernate.dialect.PointbaseDialect

PostgreSQL - org.hibernate.dialect.PostgreSQLDialect
Mckoi SQL - org.hibernate.dialect.MckoiDialect
Microsoft SQL Server - org.hibernate.dialect.SQLServerDialect
MySQL - org.hibernate.dialect.MySQLDialect
Oracle (any version) - org.hibernate.dialect.OracleDialect
Oracle 9 - org.hibernate.dialect.Oracle9Dialect
Progress - org.hibernate.dialect.ProgressDialect
FrontBase - org.hibernate.dialect.FrontbaseDialect
SAP DB - org.hibernate.dialect.SAPDBDialect
Sybase - org.hibernate.dialect.SybaseDialect
Sybase Anywhere - org.hibernate.dialect.SybaseAnywhereDialect