sql - How do i connect to a postrgresql database instance using Amazon Web Services in java code? -


I recently created an account using Amazon Web Services - it is expected that up to 24/7 database in PostgreSQL Will gain access. However, there are some documents in it that how to connect directly to a postgrascape database instance using Java code. So my question is, how do I get connected to my created database? Please be certain .getConnection code will be helpful. and then. I want to use Java code, no extension or toolkit.

Some connection code is:

  try {properties props = new property (); // using the keystore if the following line is inappropriate. Props.setProperty ("SSL", "true"); Props.setProperty ("user", "Bruce Wayne"); props.setProperty ("password", "password"); connection = DriverManager.getConnection ("jdbc: postgresql: //batcomputer.cu2oezud659w.us-west-2.rds.amazonaws.com: 5432", props); } Hold (SQLException e) {System.out.println ("Connection Failed! Test Output Console"); E.printStackTrace (); Return; }   

I guess the problem is on the line where "connection" is.

And there is an error on the terminal:

  1291-121-25: SQLGUI student $ javac -cp postgresql2.jar:. JDbCExample.java 1291-121-25: SQLGUI student $ java -cp postgresql2.jar:. JDBCExample -------- PostGraySQL JDBC Connection Test ------------ PostGraySQL JDBC Driver is Registered! connection failed! Check Output Console java.sql.SQLException: No suitable driver found for jdbc: postgresql: //batcomputer.cu2oezud659w.us-west-2.rds.amazonaws.com: 5432 at java.sql.DriverManager.getConnection ( DriverManager.java: 596) java.sql.DriverManager.getConnection at (DriverManager.java:187) on JDbCExample.main (JDBCExample.java38)   

Any help is highly appreciated!

You can not easily connect to PostGrace SQL (or any other database) without "extensions or toolkits" Are there. Specifically, the only sensible way to do this is that the JDBC interface itself is part of Java, but a database specific driver is needed to connect to a personal database.

For PostgreSQL, that is.

So you really need to:

  • ; And
  • The JDBC tutorial describes how to use JDBC PGJDBC documentation, PostGrace SQL specifies the details of specific bits, such as the JDBC URL that you used to connect to PostGLSQL. should do. It also includes example code.

    You have been ensured that PGJDBC is on your cell, connecting (without doing anything with the connection) is as simple:

      Public is void ( ) Zero throws SQLException, ClassNotFoundException {Class.forName ("org.postgresql.Driver"); String url = "jdbc: postgresql: // localhost / test? User = fred and password = secret and SSL = true"; Connection conn = DriverManager.getConnection (url); // what goods here conn.close (); }    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -