Skip to content

Instantly share code, notes, and snippets.

@BGMP
Created January 1, 2021 00:17
Show Gist options
  • Save BGMP/fc527160812ed509269b5a1306a85b3c to your computer and use it in GitHub Desktop.
Save BGMP/fc527160812ed509269b5a1306a85b3c to your computer and use it in GitHub Desktop.
Example
package cl.bgmp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class Main {
public static void main(String[] args) throws SQLException {
Connection connection = null;
String pass = "bdi2020m";
String user = "bdi2020m";
try {
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://plop.inf.udec.cl/bdi2020m";
Properties props = new Properties();
props.setProperty("user", user);
props.setProperty("password", pass);
props.setProperty("ssl", "false");
connection = DriverManager.getConnection(url, props);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return;
}
PreparedStatement statement = connection.prepareStatement("SELECT * FROM casino");
ResultSet resultSet = statement.executeQuery();
resultSet.next();
System.out.println(resultSet.getString(4));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment