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



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

Answer / 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

More Core Java Interview Questions

Difference between static methods, static variables, and static classes in Java.

1 Answers  


I want to run a simple hello world java (HelloWorld.java) program using a batch file. How can i run it and how to construct a batch file.

1 Answers   Infosys,


What is interface and its use?

8 Answers   HCL,


What is the difference between multitasking and multithreading in Java

0 Answers   Sans Pareil IT Services,


Can you extend main method in java?

0 Answers  






what is difference between String buffer and String builder?

5 Answers   Benchmark,


What are the high-level thread states in java programming?

0 Answers  


How many bits is a string in java?

0 Answers  


class{ ... ... interface myinterface{ ... ... } abstract class{ .. .. } ... .. .. } is this possible to write "Interface and/ or Abstract class inside a class ? if possible whcich one is possible is only interface? is only abstract?

2 Answers   Logica CMG,


What is hashset in java?

0 Answers  


What is concurrent hashmap and its features?

0 Answers  


What are the data types supported by java? What is autoboxing and unboxing?

0 Answers  


Categories