Select Records From Database Using Java


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Type_One
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student");
Statement s=con.createStatement();
String query="select * from bca";
s.execute(query);
ResultSet rs=s.getResultSet();
while(rs.next())
{
System.out.println("Name is="+rs.getString(1));
System.out.println("City is="+rs.getString(2));
}
s.close();
con.close();
}
catch(Exception e)
{
System.out.println("Error");
}
}
}

Comments