how can you retrive information from database by using
hashmap/arraylist ,plz explain with example briefly?
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 |
Is null or empty java?
why we cannot declare static variable inside a static method
What is boolean keyword in java?
What are the differences between processes and threads?
Why parsing is done?
Can we declare static variables in JSP page.
Can a constructor have different name than a class name in java?
Is c better than java?
Justify your answer that you can't define a method inside another method in java, if you can then how?
What's the difference between comparison done by equals method and == operator?
What are Advatages of Overloading and Overridding.
How long will it take to learn java?