Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package my_store;
- import java.sql.*;
- public class MyStoreLauncher {
- public static void main(String[] args) {
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- try {
- conn = DriverManager.getConnection("jdbc:sqlserver://localhost:3306","root", "Rekbr9422997");
- Class.forName ("com.mysql.jdbc.Driver").newInstance ();
- String sqlQuery = "SELECT * FROM users";
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sqlQuery);
- while (rs.next()) {
- int id = rs.getInt("id");
- String job = rs.getString("LOGIN");
- System.out.println("" + id +", " +job);
- }
- } catch(SQLException se) {
- System.out.println("SQLError: " + se.getMessage() + " code: " + se.getErrorCode());
- } catch (Exception e) {
- System.out.println(e.getMessage());
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- stmt.close();
- conn.close();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement