Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class dbexample {
- public dbexample () throws Exception {
- Connection connection=null;
- Statement statement = null;
- try
- {
- // Register the JDBS driver
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Database is registered");
- //Opening Database connection
- connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/dicetest", "root", "mirchi89");
- String sql = "select * from users";
- statement = connection.createStatement();
- ResultSet rs = statement.executeQuery(sql);
- while(rs.next()){
- String studentname = rs.getString("email");
- System.out.println(studentname);
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- finally {
- connection.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement