|
-
Nov 18th, 2009, 02:59 AM
#1
Thread Starter
Hyperactive Member
Connection with PostgreSQL using JSP
Hello,
I wish to use PostgreSQL as my backend from the .jsp file. Also let me know where do I put the postgresql-8.4-701.jdbc3.jar file to run. I am using NetBeans 6.7.1. Please help to cope up the situation.
Thanks a lot in advance.
Thanks & Regards.
-
Nov 18th, 2009, 04:48 AM
#2
Re: Connection with PostgreSQL using JSP
Add the jar file anywhere in your classpath (I suggest using a lib folder for 3rd party libraries).
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 18th, 2009, 05:10 AM
#3
Thread Starter
Hyperactive Member
Re: Connection with PostgreSQL using JSP
I am using the database build inside the NetBeans. But I cannot retrieve the data. What is the code to retrieve the data from the table ? Please help.
-
Nov 18th, 2009, 06:33 AM
#4
Re: Connection with PostgreSQL using JSP
Code:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import org.postgresql.Driver;
public class Test
{
public static void main(String[] args) throws SQLException
{
final Driver driver = new Driver();
final Properties properties = new Properties();
properties.setProperty("schema", "public");
properties.setProperty("user", "myuser");
properties.setProperty("password", "password");
final Connection connection = driver.connect("jdbc:postgresql://db-host:5432/mydb", properties);
final PreparedStatement statement = connection.prepareStatement("select * from pg_catalog.pg_amop");
final ResultSet results = statement.executeQuery();
while (results.next())
System.out.println(results.getInt(1));
results.close();
connection.close();
}
private Test()
{
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 18th, 2009, 06:36 AM
#5
Re: Connection with PostgreSQL using JSP
The public schema is installed by default and I have no idea what kind of data is in it.
I used Netbeans 6.7.1 and the driver came from the PostgreSQL library.
Of course you know.. user name and password need chaning, so does the hostname, port number and DB name
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|