i guess this is a newbie question...Don't seem to find it anywhere, so i thought i asked, hope you don't get mad :) I am really new to all this jsp and java thing and try to figure out what's going on.
So, I have created 2 classes that create the connection to my postgres database. The thought was to have a class that creates the connection and use it anytime i need it, cause i will need to retrieve data many times in the future.
The first one: DbContract.java
package Database;
public class DbContract
{
public static final String HOST = "jdbc:postgresql://localhost:5432/";
public static final String DB_NAME = "DB_1";
public static final String USERNAME = "postgres";
public static final String PASSWORD = "12345";
}
and the second one: TestConnection.java
package Database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class TestConnection
{
public static void main(String[] args)
{
try
{
Class.forName("org.postgresql.Driver");
Connection c;
c = DriverManager.getConnection(
DbContract.HOST+DbContract.DB_NAME,
DbContract.USERNAME,
DbContract.PASSWORD);
System.out.println("DB connected");
}
catch (ClassNotFoundException | SQLException e)
{
e.printStackTrace();
}
}
}
Now, i want to use these, in order to retrieve data from a existing database i have (postgres and it is filled with records.), BUT from a jsp page. Is it possible?
Can anyone, help me step by step to do it, or is it too easy?
thanks in advance