Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- public class Conn {
- public static void main(String[] args) {
- Connection connection2 = null;
- Statement statement2 = null;
- ResultSet resultSet2 = null;
- try {
- connection2 = (Connection) DriverManager.getConnection(
- "jdbc:mysql://localhost/ИМЯ", "ЛОГИН", "ПАРОЛЬ");
- } catch (SQLException se) {
- }
- try {
- statement2 = connection2.createStatement();
- } catch (SQLException se) {
- se.printStackTrace();
- }
- try {
- resultSet2 = statement2.executeQuery("SELECT * FROM userdetails");
- } catch (SQLException se) {
- se.printStackTrace();
- }
- try {
- ResultSetMetaData rsmd = resultSet2.getMetaData();
- int columns = rsmd.getColumnCount();
- for (int i = 1; i <= columns; i++)
- System.out.printf("%-8st", rsmd.getColumnName(i) + " ");
- System.out.println();
- for (; resultSet2.next();) {
- for (int j = 1; j <= columns; j++)
- System.out
- .printf("%-8st", resultSet2.getObject(j) + " ");
- System.out.println();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- try {
- connection2.close();
- statement2.close();
- resultSet2.close();
- } catch (SQLException se) {
- se.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement