•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 423,494 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,734 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 475 | Replies: 1
![]() |
•
•
Join Date: May 2008
Posts: 14
Reputation:
Rep Power: 1
Solved Threads: 0
hi
can any one help me to create customtag for database connection.
here i paste the which i tried,
db.java (tag handler)
---------
but it doesn't work
thanks
can any one help me to create customtag for database connection.
here i paste the which i tried,
db.java (tag handler)
---------
JAVA Syntax (Toggle Plain Text)
import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import javax.servlet.jsp.tagext.DynamicAttributes; import javax.servlet.jsp.tagext.*; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspContext; import javax.servlet.jsp.PageContext; /** * * @author cepl */ public class db extends SimpleTagSupport implements DynamicAttributes { private ArrayList keys = new ArrayList( ); private ArrayList values = new ArrayList( ); private Connection conn; private Statement stmt; ResultSet rs; public void doTag() throws JspException, IOException{ JspWriter out=getJspContext().getOut(); try { conn = DriverManager.getConnection("jdbc:derby://localhost:1527/lemsdb_new;create=true;user=lems;password=kavitha"); stmt = conn.createStatement( ); rs = stmt.executeQuery("select c_name from lems.conlist"); while(rs.next()){ String name = rs.getString("c_name"); JspContext ctx = getJspContext( ); ctx.setAttribute( "name", name ); } } catch ( SQLException e ) { System.out.println( "SQL Error :" + e.toString( ) ); } finally { try { //Closing the statement and the connection objects this.closeConnection( conn, stmt ); } catch ( Exception e ) { //Return error message on Exception System.out.println( "SQL Error :" + e.toString( ) ); } } } public void setDynamicAttribute( String uri, String localName, Object value ) throws JspException { keys.add( localName ); values.add( value ); } public void closeConnection( Connection conn, Statement stmt ) throws Exception { if ( conn != null ) { //Close the statement and connection stmt.close( ); conn.close( ); } } }
but it doesn't work
thanks
Last edited by peter_budo : Jun 2nd, 2008 at 6:48 am. Reason: Keep It Organized - please use [code] tags
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
age amd avatar backup blue gene breach business chips daniweb data data protection database development dos download economy energy enterprise europe hardware ibm ibm. news it linux mbit medicine memory microsoft network news open source openoffice pc ps3 recession red hat security server sun supercomputer supercomputing survey technology testing throughput trends ubuntu upload working x86
- Previous Thread: How to Access the value of the textbox.....
- Next Thread: Web Service / Packet Listener Smack Integration Error



Linear Mode