Jsp
How to connect to a db from jsp
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page language="java"
import="java.sql.Connection,java.sql.DriverManager,java.sql.SQLException,javax.naming.InitialContext,javax.naming.NamingException,javax.sql.DataSource;"
 %>
<%
  InitialContext ctx=null;
 DataSource ds=null;
 Connection con = null;
 
    try
   {
    ctx = new InitialContext();
    ds = (DataSource) ctx.lookup("ABC_DSN");
   }
   catch(Exception e)
   {
    System.out.println("Exception -------->");
   }
   if(ds != null)
   {
    con = ds.getConnection();
     System.out.println("Got Connected-------->");
 
     PreparedStatement ps = conn.prepareStatement("select sysdate from dual");
     ResultSet rs = ps.executeQuery();
 
     while(rs.next())
     {
       System.out.println("XXXXXXXXX);
     }
      rs.close();
      ps.close();
 
   }
 
   try {
    con.close();
   }
   catch(SQLException ex)
   {
    log.error(ex);
   } 
 %>
Advertisement
 
 
Today, there have been 1 visitors (7 hits) on this page!
=> Do you also want a homepage for free? Then click here! <=