Here's is a code snippet to connect to a database through JSP:
java Code:
String driver = "org.apache.derby.jdbc.EmbeddedDriver"; String dbName="C:\\databases\\mydb"; String connectionURL = "jdbc:derby:" + dbName; try { Class.forName(driver); } catch(java.lang.ClassNotFoundException e) { e.printStackTrace(); } try { conn = DriverManager.getConnection(connectionURL); } catch (Throwable e) { e.printStackTrace(); } stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
This is for a Derby database, not PostgreSQL, but I'm assuming if you find the appropriate driver, it shouldn't require many changes!




Reply With Quote