create a table movie (movie_no,mname,release_year).Write a java program to display information about all columns in the movie table(Use ResultsetMetaData)|EasyCoding45

In this tutorial we are going to learn how we can create a table movie (movie_no,mname,release_year).and Write a java program to display information about all columns in the movie table(by using ResultsetMetaData).

Let's get Started--


Program :-


import java.sql.*;

import java.sql.Connection;

import java.sql.DriverManager;

import java.util.*;

class movie

{

public static void main(String a[])throws Exception

{

Class.forName("com.mysql.cj.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/anand?useSSL=false&serverTimezone=Asia/Kolkata","user=root","password=admin123");

Statement st;

st=con.createStatement();

ResultSet rs=st.executeQuery("select * from movie ");

ResultSetMetaData md=rs.getMetaData();

int cnt=md.getColumnCount();

for(int i=1;i<=cnt;i++)

{

String cname=md.getColumnName(i);

System.out.print(cname+"|| ");

}

while(rs.next())

{

System.out.println("\n"+rs.getInt(1)+" ||"+rs.getString(2)+" ||"+rs.getInt(3));

}

}

}


Output :-


                                                        Thank You💚

Comments