Tuesday, July 18, 2017

Arraylist in data from database

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication39;

/**
 *
 * @author prakash
 */
import java.sql.*;
import java.util.*;
public class JavaApplication39 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try{
            Class.forName("oracle.jdbc.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system","oracle");
        Statement stm = con.createStatement();
        String s1="select * from student";
        ResultSet res = stm.executeQuery(s1);
        ArrayList<String> info= new ArrayList<String>();
        while(res.next())
        {
            info.add(res.getString(1)+res.getString(2)+res.getString(3)+res.getString(4));
        }
        for(String s2:info)
        {
            System.err.println(s2);
        }
       
        }
        catch(Exception e)
        {
            System.err.println(e);
        }
     
    }
   
}

No comments:

Post a Comment