Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package auths;
- import java.sql.*;
- /**
- *
- * @author adas
- */
- public class AuthS {
- /**
- * @param args the command line arguments
- */
- static final String DB_URL = "jdbc:mysql://someplace.ipagemysql.com/db_name";
- static final String USER = "db_user";
- static final String PASS = "db_pass";
- public static void main(String[] args) throws Exception {
- // TODO code application logic here
- AuthS as = new AuthS();
- as.connectToDB();
- }
- public void connectToDB() throws Exception{
- Connection conn = null;
- Statement stmt = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Connecting to database...");
- conn = DriverManager.getConnection(DB_URL,USER,PASS);
- System.out.println("Creating statement...");
- stmt = conn.createStatement();
- String sql;
- sql = "SELECT * from users";
- ResultSet rs = stmt.executeQuery(sql);
- while(rs.next()){
- String mUsername = rs.getString("username");
- String mHash = rs.getString("hash");
- System.out.print(", First: " + mUsername);
- System.out.println(", Last: " + mHash);
- }
- rs.close();
- stmt.close();
- conn.close();
- } catch (Exception ex) {
- }
- }
- }
Add Comment
Please, Sign In to add comment