aspose file tools*
The moose likes Struts and the fly likes Can't  create connection with oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Can Watch "Can New topic
Author

Can't create connection with oracle

Subhradip Podder
Ranch Hand

Joined: Aug 27, 2007
Posts: 36
Hi all,

I'm created a userLogin form with using struts-1.1(MyEclipse),oracle 9i,and using odbc14.jar.
The problem is when i'm written loginAction.java I get bellow error message.

oracle cannot be resolved to a type

given bellow is my loginAction.java code.

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.iotde.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.iotde.struts.form.LoginForm;
import javax.servlet.http.HttpSession;

import java.sql.*;
import java.io.*;



/**
* MyEclipse Struts
* Creation date: 10-04-2007
*
* XDoclet definition:
* @struts.action path="/login" name="loginForm" input="/login.jsp" scope="request" validate="true"
* @struts.action-forward name="success" path="success.jsp"
* @struts.action-forward name="failure" path="failure.jsp"
*/
public class LoginAction extends Action {
/*
* Generated Methods
*/

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
LoginForm loginForm = (LoginForm) form;
String username = loginForm.getUsername();
String password = loginForm.getPassword();
HttpSession session = request.getSession();

//get connection from database
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

Connection conn=DriverManager.getConnection ("jdbc racle:thin:@172.16.90.139:1521 ROD","apps","apps");

Statement smt = conn.createStatement();
ResultSet rs;

String query="select first_name,password from users where first_name='"+username+"' and password='"+password+"'";
rs=smt.executeQuery(query);
while(rs.next())
{
String name = rs.getString("first_name");
String pwd = rs.getString("password");
if (username.equalsIgnoreCase("name") &&
password.equals("pwd"))
{
// we are in
return mapping.findForward("success");
} else
{
// not allowed
return mapping.findForward("failure");
}

}
smt.close();
rs.close();
conn.close();


}

private Object getSession() {
// TODO Auto-generated method stub
return null;
}
}



i'm trying to solve this problem many times but i'm fail....... please help me.....
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One possible cause for this error could be that you haven't included the ojdbc14.jar file in the Java build path for your project.


Merrill
Consultant, Sima Solutions
Subhradip Podder
Ranch Hand

Joined: Aug 27, 2007
Posts: 36
Originally posted by Subhradip Podder:
Hi all,

I'm created a userLogin form with using struts-1.1(MyEclipse),oracle 9i,and using odbc14.jar.
The problem is when i'm written loginAction.java I get bellow error message.

oracle cannot be resolved to a type

given bellow is my loginAction.java code.

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.iotde.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.iotde.struts.form.LoginForm;
import javax.servlet.http.HttpSession;

import java.sql.*;
import java.io.*;



/**
* MyEclipse Struts
* Creation date: 10-04-2007
*
* XDoclet definition:
* @struts.action path="/login" name="loginForm" input="/login.jsp" scope="request" validate="true"
* @struts.action-forward name="success" path="success.jsp"
* @struts.action-forward name="failure" path="failure.jsp"
*/
public class LoginAction extends Action {
/*
* Generated Methods
*/

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
LoginForm loginForm = (LoginForm) form;
String username = loginForm.getUsername();
String password = loginForm.getPassword();
HttpSession session = request.getSession();

//get connection from database
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

Connection conn=DriverManager.getConnection ("jdbc racle:thin:@172.16.90.139:1521 ROD","apps","apps");

Statement smt = conn.createStatement();
ResultSet rs;

String query="select first_name,password from users where first_name='"+username+"' and password='"+password+"'";
rs=smt.executeQuery(query);
while(rs.next())
{
String name = rs.getString("first_name");
String pwd = rs.getString("password");
if (username.equalsIgnoreCase("name") &&
password.equals("pwd"))
{
// we are in
return mapping.findForward("success");
} else
{
// not allowed
return mapping.findForward("failure");
}

}
smt.close();
rs.close();
conn.close();


}

private Object getSession() {
// TODO Auto-generated method stub
return null;
}
}



i'm trying to solve this problem many times but i'm fail....... please help me.....



Hi Merrill,

Thanks for your suggestion,i think you will correct.
but i don't know that what is the process of included the ojdbc14.jar file in the Java build path for any project.
Kindly tell me about this.

Also my <data-sources> of struts-config.xml is bellow

<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<set-property property="url" value="jdbc racle:thin:@172.16.90.139:1531 ROD"/>
<set-property property="username" value="apps"/>
<set-property property="password" value="apps"/>
</data-source>
</data-sources>

but i doesn't found following path
"org.apache.commons.dbcp.BasicDataSource"

and i get follow bellow error message.

HTTP Status 404 - Servlet action is not available

type Status report
message Servlet action is not available
description The requested resource (Servlet action is not available) is not available


i'm waiting for your valuable Suggestion.................
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Regarding your first question: I don't use MyEclipse, but I know that with plain Eclipse, you can add jar files to the build path of a project by right-clicking the project, selecting properties and then selecting Java Build Path. Click the Libraries tab and then click the Add external Jar files button. Please understand that the above process takes care of your compile-time classpath only. At run-time, you will have to include the ojdbc14.jar file in your Application Server's classpath.

Regarding your second question: I would advise you not to use the Struts Data Source Utility. As I look at your code, you're not using it to get the connection anyway. For more information on this, see question 7 of this forum's FAQ.
[ October 15, 2007: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't create connection with oracle