Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Oracle in Struts application?

 
sarang bharambe
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sanat
Ranch Hand
Posts: 111
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sorry to mentioned i had tested the above code Using weblogic 8.1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic