[PostgreSQL] JDBC 연동
postgresql-9.3-1102.jdbc41.jar
mpoimport java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class ConnetctionPostgreSQL {
public static void main(String[] args) {
//THIS IS PostgreSQL JDBC Simple Sample by won chan sic (2014.11.18)
System.out.println("HI");
String url = "jdbc:postgresql://localhost/wonword";
Properties props = new Properties();
props.setProperty("user", "postgres");
props.setProperty("password", "1q2w3e");
//props.setProperty("ssl", "true");
try{
Connection conn = DriverManager.getConnection(url,props);
//*********************************************************************************
// SELECT
//*********************************************************************************
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT USER_ID, USER_PW FROM USERS");
while(rs.next())
{
System.out.println( rs.getString(1) + "/"+ rs.getString(2));
}
rs.close();
st.close();
//*********************************************************************************
//*********************************************************************************
// INSERT
//*********************************************************************************
// Statement stmt = null;
// stmt = conn.createStatement();
//
// String sql = "INSERT INTO USERS(USER_ID, USER_PW) VALUES ('한글','테스트')";
// stmt.executeUpdate(sql);
//
// stmt.close();
//*********************************************************************************
}catch( Exception e ){
System.out.println(e.toString());
}
}
}
rt