JDBC Connection code to get Name and roll no. of student from database Students.
import java.sql.*;
public class jdbc_select
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Students");
Statement st=conn.createStatement();
String sql1="select * from Student ";
ResultSet rs=st.executeQuery(sql1);
while(rs.next())
{
System.out.println(rs.getString("Roll_no"));
System.out.println(rs.getString("Name"));
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
No comments:
Post a Comment