File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to use Oracle in Struts application? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use Oracle in Struts application?" Watch "How to use Oracle in Struts application?" New topic
Author

How to use Oracle in Struts application?

sarang bharambe
Ranch Hand

Joined: Apr 01, 2005
Posts: 40
hey friends
I am learning struts Framework and using Oracle as backend.But i dont know how to use it.can anyone tell what i have to do for it?What drivers I would be needing? and the datasource configuration?Currently i am using mysql as backend.

regards


SCJP 1.4 (86%)<br />SCWCD 1.4 (86%)<br />----------<br />If You dont succeed at first time,call it Version 1.0 !!!
sanat
Ranch Hand

Joined: Dec 08, 2004
Posts: 111

Hi sarang,

If you are already using MySQL, then you don't need to update much of your code. You need to change some details in struts-config.xml file or web.xml file.

Oracle comes with the drivers you need to use, so don't worry about the drivers. Oracle comes with Type2 OCI driver and Type4 pure Java driver.

Hope this helps.
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Originally posted by sarang bharambe:
hey friends
I am learning struts Framework and using Oracle as backend.But i dont know how to use it.can anyone tell what i have to do for it?What drivers I would be needing? and the datasource configuration?Currently i am using mysql as backend.

regards

Hi little bit specific

this is how u can use

public class StudentDao
{
Connection con = null;
Statement st = null;
ResultSet rs = null;
DataSource ds = null;
Context ctx = null;
String item = null;
String value = null;
boolean flag = false;
String skill= null;
String jcode = null;
String loc = null;
String pos = null;
String desc = null;
int max = 0;
int min = 0;
//HttpSession workSession = null;
//workSession = req.getSession(true);


public static void display()
{
System.out.println(" i am from dao display");
}

public Collection getSubjects() throws Exception
{
ArrayList list = new ArrayList();
try
{
Properties p = System.getProperties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx = new InitialContext(p);
ds = (DataSource) ctx.lookup("RmsJndi2");
con = ds.getConnection();
st = con.createStatement();
con.setAutoCommit(true);
rs = st.executeQuery("select * from combo");

while(rs.next())
{
item = (String) rs.getString("item");
value = (String) rs.getString("value");
System.out.println(item+" "+value);
list.add(new SubjectBean(value,item));
}// while
} // try
catch(Exception e )
{
System.out.println(" Exception error "+e.getMessage());
}
finally
{
con.close();
st.close();
//rs.close();
}// finally
return list;
}// fn get subjects

}


as usal DAO pattern u can use ...

if u use <datasource> that becomes problem in performance issue slater if u didnt designur code well.....

Lt me know if this help u



Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi sorry to mentioned i had tested the above code Using weblogic 8.1
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Oracle in Struts application?
 
Similar Threads
Understanding Struts
No suitable driver using msql
dtds in struts
PDK and Struts
How can i display the record in JSP Using Struts with Hibernate?