import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class SampleApp {
public static void
main(String[] args) throws ParseException, ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/SampleFileDb","root","root");
Statement
stm=con.createStatement();
ResultSet
rs=stm.executeQuery("select * from datas");
ResultSetMetaData rsmd=rs.getMetaData();
int
colcount=rsmd.getColumnCount();
System.out.println("columns: "+colcount);
for(int
i=1;i<=colcount;i++)
{
System.out.println("Column Name of "+i+"
column: "+rsmd.getColumnName(i));
System.out.println("Column Type Name of "+i+"
column: "+rsmd.getColumnTypeName(i));
}
int i=0;
List<String> ls=new ArrayList<>();
while(rs.next())
{
for(int y=1;y<=colcount;y++)
{
ls.add(rs.getString(y));
}
System.out.println(ls);
ls.clear();
}
}
}
No comments:
Post a Comment