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
Difference between linkedlist and arraylist.
Can we have try without catch block?
Why is java architectural neutral?
How to sort numbers in java without array?
Explain creating threads by implementing runnable class?
How to create a custom exception?
What is string pooling concept?
What is functional interface in java example?
What is meant by vector class, dictionary class, hash table class, and property class?
What is the epoch date?
Mention some features of java?
What is the difference between replace and replace all?
What is the basic concepts of OOPS?
Is 0 true or false in java?
Can set contain duplicates?