Description:
Java JDBC is a java API to connect and execute query with the database. JDBC API uses jdbc drivers to connect with the database.
Learn through my videos:

Program:
package com.telusko.jdbcdemo;
import java.sql.*;
importjava.util.logging.Logger;
publicclass JdbcDaoDemo {

	publicstaticvoid main(String[] args) {
		StudentDao dao=new StudentDao();
		Student s1=dao.getStudent(12);
		System.out.println(s1.sname);

	}

}
class StudentDao
{
	public Student getStudent(introllno)
	 {
		
		try {
			 String query="select sname from student where rollno="+rollno;
			 Student s=new Student();
			s.rollno=rollno;
			 Class.forName("com.mysql.jdbc.Driver");
			 Connection con=DriverManager.getConnection("{Connection String}", "{username}", "{password}");
			  Statement st=con.createStatement();
			 ResultSet rs=st.executeQuery(query);
			rs.next();
			String name=rs.getString(1);
			s.sname=name;
			returns;
		     }
		catch (Exceptione) {
			System.out.println(e);
		}
		returnnull;
		
		
	 }
}
class Student
{
	introllno;
	 String sname;
}
Output:
{output from database}
Logic:
The above codes are basic step for making connection with the database we are doing it with mysql database  .In the connection string we need to pass the username and password of mysql .The statement object allow you to The term "result set" refers to the row and column data contained in a ResultSet object.send sql querry . A ResultSet object maintains a cursor that points to the current row in the result set.