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

What is the use of accept () method in java?

611


Explain method overloading?

573


What is an example of character?

554


How can you set the applet size?

579


Can I overload to string method

968






Is array an object in java?

556


What is the main use of generics in java?

510


How to reverse a string in java?

526


What do you mean by boolean?

580


What is use of static method?

536


Explain the concept of proper inheritance?

621


does java support pointers?

566


Which browsers work with java?

563


Can we serialize static variables in java?

655


What are data structures in java?

535