| Author |
Struts: DB Connection
|
Lalit Vora
Ranch Hand
Joined: Jun 22, 2006
Posts: 37
|
|
|
Hi, I want to connect to DB for extracting data from oracle DB. Please guide me how to connect to DB to retrieve data?
|
 |
Carla carmona
Greenhorn
Joined: Oct 14, 2004
Posts: 14
|
|
Hi there ! Try this link and let me know if is of any good to you. http://struts.apache.org/struts-doc-1.1/faqs/database.html Jose Cardoso Jr
|
 |
Lalit Vora
Ranch Hand
Joined: Jun 22, 2006
Posts: 37
|
|
No, I am getting same error every time This is my struts config.xml I am getting Error HTTP 404 servlet action not available. If i am not using dtasource and changing action class my application runs without datasource and gets hard coded value from getquote method. I want value from db <struts-config> <data-sources> <data-source type="org.apache.common.dbcp.BasicDataSource"> <set-property property="driverClassName" vlaue="oracle.jdbc.driver.OracleDriver"/> <set-property property="url" vlaue="jdbc racle:thin: @(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521))(CONNECT_DATA=(SID=orcl)))"/> <set-property property="username" vlaue="scott"/> <set-property property="password" vlaue="tiger"/> </data-source> </data-sources> <form-beans> <form-bean name="lookupForm" type="ch03.LookupForm"/> </form-beans> <action-mappings> <action path="/Lookup" type="ch03.LookupAction" name="lookupForm"> <forward name="success" path="/quote.jsp"/> <forward name="failure" path="/index.jsp"/> </action> </action-mappings> <message-resources parameter="MessageResources" /> </struts-config> This is my action class public class LookupAction extends Action { public Double getQuote(String symbol, HttpServletRequest request) throws Exception { Double price=null; Connection conn=null; Statement stmt=null; ResultSet rs=null; DataSource dataSource=null; try { dataSource = getDataSource(request); conn= dataSource.getConnection(); stmt= conn.createStatement(); rs= stmt.executeQuery("select * from stocks where" + "symbol='" + symbol +"'"); if (rs.next()) { double tmp=0; tmp = rs.getDouble("price"); price= new Double(tmp); System.err.println("price:" +price); } else { System.err.println("Symbol not found returning null"); } } catch(SQLException e) { System.err.println(e.getMessage()); } finally { if (rs!= null) { try { rs.close(); } catch (SQLException sqle) { System.err.println(sqle.getMessage()); } rs=null; } if (stmt!=null) { try{ stmt.close(); } catch (SQLException sqle) { System.err.println(sqle.getMessage()); } stmt=null; } if (conn!=null) { try{ conn.close(); } catch (SQLException sqle) { System.err.println(sqle.getMessage()); } conn=null; } } return price; } public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ Double price=null; String target=new String("success"); if(form !=null) { LookupForm lookupForm = (LookupForm) form; String symbol = lookupForm.getSymbol(); price = getQuote(symbol,request); } if(price == null) { target = new String("failure"); } else { request.setAttribute("PRICE",price); } return(mapping.findForward(target)); } } Please Guide me its very urgent. I also want to know do we require any driver to place anywhere? Also without using struts config can i directly connect to DB? Please help me Thanks Lalit
|
 |
NV Krishna
Greenhorn
Joined: Mar 23, 2005
Posts: 14
|
|
<struts-config> <data-sources> <data-source type="org.apache.common.dbcp.BasicDataSource"> <set-property property="driverClassName" vlaue="oracle.jdbc.driver.OracleDriver"/> <set-property property="url" vlaue="jdbc racle:thin: @(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521))(CONNECT_DATA=(SID=orcl)))"/> Hi, Place the classes12.jar in the classpath (if you are using oralce). change the struts-config.xml in <data-source> section, like this. <set-property property="url" value="jdbc racle:@thin:myhost:1521 rcl/> hope it will work.
|
 |
 |
|
|
subject: Struts: DB Connection
|
|
|