Jdbc program to retrieve data from database

Retrieve data from database

This program illustrate the concept of Jdbc program to retrieve data from database.Jdbc stands for java database connectivity.It is an application programming interface (API) for the programming language Java, which defines how a client may access a database.

Program

import java.sql.*;
class scan
{
public static void main(String arg[])
 {
   String url="jdbc:mysql://localhost:3306/java";
   String user="root";
   String pass="";

   try
   {
    Class.forName("com.mysql.jdbc.Driver");
	Connection con=DriverManager.getConnection(url,user,pass);
	Statement s1=con.createStatement();
	ResultSet r1=s1.executeQuery("select * from info");
	
	while(r1.next())
	{
		System.out.println(r1.getString(1)+"   "+r1.getInt(2));
	}
	
	con.close();
   }
   
   catch(Exception e)
   {
	   System.out.println(e);
   }

   }
}

Table

Retrieve data from database

Output

Retrieve data from database


Comment below if you are facing any problem and subscribe to our news letter for more updates.


Also read

Java swing program to change label text on button click
Java swing program to make signup form
Java program to connect two swing frames
Java program to transpose a matrix
Java program to display sum of two input numbers in applet


Summary
Jdbc program to retrieve data from database
Article Name
Jdbc program to retrieve data from database
Description
This program illustrate the concept of Jdbc program to retrieve data from database.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *