Created
June 19, 2021 03:54
-
-
Save extsalt/2ad18a53f546d35f9f7ac9475e42018e to your computer and use it in GitHub Desktop.
Read from database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.*; | |
public class Main { | |
public static void main(String... args) throws ClassNotFoundException, SQLException { | |
Connection connection = null; | |
//Loading of driver | |
Class.forName("com.mysql.cj.jdbc.Driver"); | |
// Getting connection from driver | |
connection = DriverManager.getConnection("jdbc:mysql://localhost/srgp?user=root&password="); | |
Statement statement = connection.createStatement(); | |
ResultSet resultSet = statement.executeQuery("select * from students"); | |
System.out.println("Id\t\tName\tEno\tGender\tEmail"); | |
while (resultSet.next()) { | |
System.out.println( | |
resultSet.getInt("id") + "\t\t" + | |
resultSet.getString("name") + "\t" + | |
resultSet.getString("e_no") + "\t" + | |
resultSet.getString("gender") + "\t" + | |
resultSet.getString("email") | |
); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment