how can you retrive information from database by using
hashmap/arraylist ,plz explain with example briefly?

Answer Posted / none

import java.util.*;
import java.sql.*;

public class Jdbc
{
public static void main(String[] a)
{
Connection conn=null;
try
{
String s1="Driver name for registration";
Class.forname(s1);
String url="Driver Port No name";
String username="Database Username";
String password="Database password";

conn=Drivermanager.getConnection(url,username,password);
String sql="SELECT name,address FROM tb"
Statement stmt=conn.createStatement(sql);
Resultset rs=stmt.executeQuery();

ArrayList al=new List();
while(rs.hasnext())
{
al.add(index,rs.getString());
}
rs.close();
stmt.close();
conn.close();
}
//handle Exceptions
}
}

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between linkedlist and arraylist.

795


Can we have try without catch block?

846


Why is java architectural neutral?

839


How to sort numbers in java without array?

725


Explain creating threads by implementing runnable class?

801


How to create a custom exception?

740


What is string pooling concept?

766


What is functional interface in java example?

753


What is meant by vector class, dictionary class, hash table class, and property class?

894


What is the epoch date?

733


Mention some features of java?

730


What is the difference between replace and replace all?

684


What is the basic concepts of OOPS?

906


Is 0 true or false in java?

727


Can set contain duplicates?

757