Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
JavaCodeBasics/JavaDb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (37 sloc)
1.35 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dbjava; | |
import java.sql.*; | |
/** | |
* | |
* @author sareenv | |
*/ | |
public class DBJava { | |
/** | |
* @throws java.sql.SQLException | |
*/ | |
public void databaseConnection() throws SQLException{ | |
// String connectionUrl = "jdbc:derby://localhost:1527/newdb"; | |
String connectionUrl1 = "jdbc:mysql://us-cdbr-iron-east-03.cleardb.net/heroku_64c1b2d2353b04c"; | |
String userName = "be0bd21ceb4d83"; | |
String password = "ecaf4504"; | |
Connection conn = DriverManager.getConnection(connectionUrl1, userName, password); | |
if (conn != null){ | |
System.out.println("System is getting connection to the database"); | |
Statement st; | |
st = conn.createStatement(); | |
ResultSet rs = null; | |
// Start getting data from the database | |
String sqlQuery = "SELECT * FROM weakAuth"; | |
rs = st.executeQuery(sqlQuery); | |
while(rs.next()){ | |
System.out.println(rs.getString("email")); | |
} | |
}else{ | |
System.out.println("Not connected to this yet"); | |
} | |
} | |
public static void main(String[] args) throws SQLException { | |
// TODO code application logic here | |
DBJava dbConnection = new DBJava(); | |
dbConnection.databaseConnection(); | |
} | |
} |