Powered by Blogger.

Program for User defined Exception in java

>> Monday, April 18, 2011

To create user defined exception first you should create a class by extending Exception class.

class BadString extends RuntimeException{

}

Create  another class  named as "UserExcep" to throw our own exception.

public class UserExcep


Write some logical conditions to throw your exception and the exception caught by catch block.

package javabynataraj.exceptions;

import java.io.BufferedReader;
import java.io.InputStreamReader;

class BadString extends RuntimeException{

}
public class UserExcep{
    public static void main(String[] args) {
        try{
            System.out.println("Enter the String: ");
            BufferedReader sb=new BufferedReader(new InputStreamReader(System.in));
            String s=sb.readLine();
            if(s.equals("hateyou")){
                throw new BadString();
            }
            System.out.println("I Accept your String");
        }catch(Exception e){
            System.out.println("Please enter a good String");
            //e.printStackTrace();
        }
    }
}


Introduction to Java Programming, Comprehensive (8th Edition)

Read more..

What is Serialization? Write a Simple program in java using Serialization?

>> Saturday, April 16, 2011

"Serialization is the process of converting the data(Objects) into stream of bytes and storing in to the files or database."

Serialization in Java with Simple program_JavabynataraJ

We can do the Serialization process by implementing Serializable interface.

class SerialDemo implements java.io.Serializable.

The above step tells the compiler that you are going to implement serialization.
Which basically means that the object is going to be saved or persisted.

Read more..

Upload CSV file into MySql Database based on columns using Servlets and Java

>> Tuesday, April 12, 2011

The CSV file is having multiple values to insert in perticular columns and rows in mysql database.

Here we have two files so we have to insert in two tables .

one is Header part file

another is Detail part file

Basically these two are to upload the questions and answers into the examination portal to upload question papers and answer paper in (Merit Tracking System project).

First we have to do the things are Uploaded file has to save in perticular folder and then they have to insert the values into the database table.This is our main task to do.

Read more..

Types of JDBC Drivers

>> Saturday, April 9, 2011

JDBC drivers are divided into four types or levels. The different types of jdbc drivers are:

Type 1: JDBC-ODBC Bridge driver (Bridge)
Type 2: Native-API/partly Java driver (Native)
Type 3: AllJava/Net-protocol driver (Middleware)
Type 4: All Java/Native-protocol driver (Pure)

4 types of jdbc drivers are elaborated in detail as shown below:

Type 1 JDBC Driver

JDBC-ODBC Bridge driver
The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available.
JDBC Type Driver 1

Read more..

JDBC - CallableStatement IN, OUT, INOUT parameters

>> Friday, April 8, 2011

Callable Statement in Brief_JavabynataraJThe CallableStatement interface allows the use of SQL statements to call stored procedures. Stored procedures are programs that have a database interface.
These programs possess the following:
1)    They can have input and output parameters, or parameters that    are   both input and output.
2)    They can have a return value.
3)    They have the ability to return multiple ResultSets.

Conceptually in JDBC, a stored procedure call is a single call to the database, but the program associated with the stored procedure may process hundreds of database requests. The stored procedure program may also perform a number of other programmatic tasks not typically done with SQL statements.

Read more..

JDBC - Simple Statement

The Statement interface lets you execute a simple SQL statement with no parameters. The SQL instructions are inserted into the Statement object when the Statement.executeXXX method is called.

Query Statement: This code segment creates a Statement object and calls the Statement.executeQuery method to select text from the dba database. The results of the query are returned in a ResultSet object. How to retrieve results from a ResultSet object is explained in Result Sets below.



Statement stmt = con.createStatement();
 ResultSet results = stmt.executeQuery("SELECT TEXT FROM dba ");


Update Statement: This code segment creates a Statement object and calls the Statement.executeUpdate method to add an email address to a table in the dba database.

  String updateString =  "INSERT INTO dba VALUES (some text)";
  int count = stmt.executeUpdate(updateString);

Read more..

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.