java - Name [dsjndi] is not bound in this Context. Unable to find [dsjndi] -
i'm trying use jdbc connection pool, create intialcontext obj , datasource obj, , give "dsjndi" parameter of lookup method of initialcontext, when run project project shows ""name [dsjndi] not bound in context. unable find [dsjndi]."" problem can guide me?
connection con = null; statement st = null; resultset rs = null; resultsetmetadata rsmd = null; public void process(httpservletrequest req, httpservletresponse res) throws servletexception, ioexception { //general settings //get print writer obj printwriter pw = res.getwriter(); //set content type res.setcontenttype("text/html"); //read form data string tablename = req.getparameter("table"); try { //get con obj jdbc con pool con = makeconnection(); //create statement obj st = con.createstatement(); //execute query rs = st.executequery("select * form" +tablename); //use metadata obj db vlaues along col names rsmd = rs.getmetadata(); int cnt = rsmd.getcolumncount(); pw.println("<hmtl><body bgcolor='#ffffa9'>"); pw.println("<center><h3>the details of table" +tablename); pw.println("<br><br><table cellsapcing='1' bgcolor='#00ff00'>"); pw.println("<tr bgcolor='#ffffa9'>"); //pritnt col names for(int col=1;col<=cnt;col++) { pw.println("<th>" +rsmd.getcolumnlabel(col)+ "  "); } pw.println("</tr>"); //print col values while(rs.next()) { pw.println("<tr bgcolor='#ffffa9'>"); for(int i=1;i<=cnt;i++) { pw.println("<td>" +rs.getstring(i)+ " </td>"); } pw.println("</td>"); }//while pw.println("<table><br/>"); pw.println("<b>to view table</b><ahref='index.html'>click here</a>"); pw.println("</body></html>"); }//try catch(exception e) { e.printstacktrace(); } } private connection makeconnection() { connection con = null; try { //get intialconetext initialcontext ic = new initialcontext(); //get data sourse obj datasource ds = (datasource) ic.lookup("dsjndi"); //get jdbc con obj con pool con = ds.getconnection(); }//try catch(exception e) { e.printstacktrace(); } return con; }//make connection public void doget(httpservletrequest req, httpservletresponse res) throws servletexception, ioexception { process(req,res); } public void dopost(httpservletrequest req, httpservletresponse res) throws servletexception, ioexception { process(req,res); }
}
Comments
Post a Comment