Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package raport;
- import java.sql.*;
- public class DBConnect {
- private Connection con;
- private Statement st;
- private ResultSet rs;
- //Connect to MySQL
- public DBConnect () {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost:3307/acraport","root","usbw");
- st = con.createStatement();
- }catch(Exception ex) {
- System.out.println("Error: "+ex);
- }
- }
- //IO query
- public void getData(String query) {
- try {
- rs = st.executeQuery(query);
- System.out.println("Recors from Database");
- while(rs.next()) {
- String test_id = rs.getString("Id");
- String test_login = rs.getString("Login");
- String test_password = rs.getString("Password");
- System.out.println("Id: "+test_id+" Login: "+test_login+" Password: "+test_password);
- }
- }catch(Exception ex) {
- System.out.println("Error: "+ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement