Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
891 B
2
Indexable
Never
package bbn243;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Connect {
	public static void main(String[]args) {
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			System.out.println("Driver loaded");
			Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/bbn243","root","root");
			if(con!=null)
				System.out.println("Database Connected");
			Statement stmt=con.createStatement();
			ResultSet rs=stmt.executeQuery("select*from userid");
			while(rs.next()) {
				System.out.println("ID:"+rs.getString(1));
				System.out.println("Password:"+rs.getString(2));
				System.out.println("Full Name:"+rs.getString(3));
				System.out.println("Email id:"+rs.getString(4));
				
			}
			con.close();
		}
		catch(Exception e) {
			System.out.println(e);
		}
	}
Leave a Comment