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
What is variable and example?
What type of language is java?
When should we create our own custom exception classes?
How does compareto work in java?
Explain about public and private access specifiers?
What is the difference between integer parseint and integer valueof?
What is the collection interface?
What do the thread?class methods run() and start() do?
How many types of classes are there in java?
What are basic data types?
Are static members inherited to sub classes?
What is the difference between the prefix and postfix forms of the ++ operator?
Explain thread in java?
How can I right-justify a string?
How do I get a substring?