Created
November 15, 2017 13:50
-
-
Save yasincidem/4b37a596f96634a5b54e08bc79453be6 to your computer and use it in GitHub Desktop.
more secure mysql connection through jdbc
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
import java.sql.*; | |
/** | |
* Created by yasin_000 on 15.11.2017. | |
*/ | |
public class Database { | |
static final String JDBC = "com.mysql.jdbc.Driver"; | |
static final String DB_URL = "jdbc:mysql://localhost:3306/world"; | |
public static void main(String[] args) { | |
try { | |
Class.forName(JDBC); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
try (Connection connection = DriverManager.getConnection(DB_URL, "root", "951753yasin@@"); | |
PreparedStatement statement = connection.prepareStatement("SELECT * FROM country WHERE population < 10000"); | |
ResultSet resultSet = statement.executeQuery()){ | |
while(resultSet.next()) | |
System.out.println(resultSet.getString("Name")); | |
} catch (SQLException e1) { | |
e1.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment