Category: Java

Define a class to declare an integer array of size n and accept the elements into the array.

import java.util.Scanner;class LinearSearch{public static void main(String args[]){int c, n, search, array[];Scanner in = new Scanner(System.in);System.out.println(“Enter number of elements”);n = in.nextlnt();array= new int[n];System.out.println(“Enter those” +n+ “elements”);for (c = 0; c < n; c++)array[c] = in.nextlnt();System.out.println(“Enter value to find”);search = in.nextlnt();for (c = 0; c < n; c++){if (array[c] = search) /Searching element is present/{System.out.println(array[c]);break;}}if (c = […]

File handling

FILE HANDLING: File handling in java comes under input output (IO) operations. Classes used in file handling in Java are present Java IO package (java.io). Some of the file handling operations are: Create file Delete file Read file Write file Changes file permissions, etc. Program for create operation in file handling: package com.journaldev.files; import java.io.File; […]

CLOSE THE DATABASE CONNECTION

CLOSE THE DATABASE CONNECTION: It is not necessary to close the connection, but open database can cause problems, so its better to close the database connection. For this close( ) method is used. Syntax: stmt.close( ); Here, stmt is statement object to be closed. cn.close( ); Here, cn is the connection object to be closed.

Process the result

The result of the SQL statement (SQL queries) are stored in a ResultSet object. To retrieve the data from the ResultSet we need to use the getXXX methods. These methods retrieve the data and convert it to a Java data type. There is a separate getXXX methods for each datatype. For example, getString( ) is […]

Execute an SQL Statement

EXECUTE AN SQL STATEMENT: There are three methods to execute the statement, which are execute( ), executeQuery( ) and executeUpdate( ). Syntax: stmt.execute( ); stmt.execute( String str); Syntax: stmt.executeQuery( ); stmt.executeQuery( String str); Syntax: stmt.executeUpdate( ); stmt.executeUpdate( String str );

EasyExamNotes © 2023