2014-04-06 4 views
0

나는 패키지 도우미, ProcessBean.java 및 DBHandler.java기호, 기호를 찾을 수 없습니다 : 변수 DBHandler 위치 : 클래스 ProcessBean

ProcessBean.java에 두 개의 클래스가 있습니다

package helpers; 

import java.util.*; 
import java.sql.*; 

public class ProcessBean implements java.io.Serializable { 
    public ProcessBean() {} 

    public String processRequest(String option) { 
    String query = ""; 
     String type = option.split("|")[0]; 
     int id = Integer.parseInt(option.split("|")[1]); 

     if(type.equals("category")) 
      query = "Select * from products where categoryId="+id; 
     else if(type.equals("vendor")) 
      query = "Select * from products where vendorId="+id; 
     else 
      query = "select * from products"; 

     Vector<String []> v = DBHandler.doQuery(query); 
     return DBHandler.getQueryResultTable(v); 
    }  
} 

DBHandler.java :

package helpers; 

import java.util.*; 
import java.sql.*; 

public class DBHandler implements java.io.Serializable { 

    public static Vector<String []> doQuery(String s) { 
     String user = "xxx"; 
     String password = "xxx"; 
     String database = "xxx"; 
    String connectionURL = "jdbc:mysql://opatija:3306/" + database + 
      "?user=" + user + "&password=" + password;  
    Connection connection = null; 
    Statement statement = null; 
    ResultSet resultSet = null; 
     Vector<String[]> v = new Vector<String[]>();   

    try { 
     Class.forName("com.mysql.jdbc.Driver").newInstance(); 
     connection = DriverManager.getConnection(connectionURL); 
     statement = connection.createStatement(); 
     resultSet = statement.executeQuery(s); 

      ResultSetMetaData md = resultSet.getMetaData(); 
      int numCols = md.getColumnCount(); 

      while(resultSet.next()) { 
       String [] tmp = new String[numCols]; 
       for(int i=0; i < numCols; i++) 
        tmp[i] = resultSet.getString(i+1); // resultSet getString is 1 based 
       v.add(tmp);     
        } 
     } 
     catch(Exception e) { 
      e.printStackTrace(); 
      }   
     finally { 
      try { 
       resultSet.close(); 
       statement.close();     
       connection.close(); 
       } 
      catch(SQLException e) {} // don't do anything if the connection is not open. 
     } 
     return v; 
    } 
    public static int doUpdate(String s) { 
     String user = "xxx"; 
     String password = "xxx"; 
     String database = "xxx"; 
     String connectionURL = "jdbc:mysql://opatija:3306/" + database + 
      "?user=" + user + "&password=" + password;  
     Connection connection = null; 
     Statement statement = null; 
     int result = -1; 

    try { 
     Class.forName("com.mysql.jdbc.Driver").newInstance(); 
     connection = DriverManager.getConnection(connectionURL); 
     statement = connection.createStatement(); 
      result = statement.executeUpdate(s); 
      } 
    catch(Exception e) { 
     e.printStackTrace(); 
     }   
     finally { 
      try { 
       statement.close();     
       connection.close(); 
       } 
      catch(SQLException e) {} // don't do anything if the connection is not open. 
     } 
     return result; 
    } 

    public static String getQueryResultTable(Vector<String []> v) { 
     StringBuffer toReturn = new StringBuffer(); 
    toReturn.append("<table>"); 
    for(int i=0; i < v.size(); i++) { 
     String [] tmp = v.elementAt(i); 
     toReturn.append("<tr>");   
     for(int j=0; j < tmp.length; j++) 
      toReturn.append("<td>" + tmp[j] + "</td>"); 
     toReturn.append("</tr>"); 
     } 
    toReturn.append("</table>"); 
    return toReturn.toString(); 
    }      
}    
내가 ProcessBean를 컴파일하고 때210

, 나는

ProcessBean.java:21: error: cannot find symbol 
Vector<String []> v = DBHandler.doQuery(query); 
          ^ 
symbol: variable DBHandler location: class ProcessBean 
ProcessBean.java:22: error: cannot find symbol 
return DBHandler.getQueryResultTable(v); 
       ^ 
symbol: variable DBHandler location: class ProcessBean 
2 errors 

내가 서버에 연결 notepad++, macxQuartz을 사용하여이 오류를 '헬퍼'폴더로 CD 모든 방법을 얻을 다음 명령 -

javac ProcessBean.java 

두 파일 모두 서버의 폴더 도우미 아래에 있으며 DBHandler이 성공적으로 컴파일되었습니다. 모든 것을 시도했지만 그것을 이해할 수는 없습니다.

도움이 매우 감사합니다.

+0

벡터를 올바르게 사용하지 않거나 올바른 벡터를 가져 오지 못합니다.어느 쪽이든 문제는 벡터에 있습니다. –

+0

오, 신경 쓰지 마세요, 죄송합니다. 오류 메시지는 정말 분명하지 않습니다. –

답변

0

내가 다음 서버에 '도우미'를 폴더로 CD 모든 방법을 연결 ++, Mac 및 xQuartz을 메모장을 사용하여이 명령 - helpers의 상위 폴더에 javac의의 ProcessBean.java

하고 다음 컴파일 명령을 사용하십시오.

javac -d . helpers/ProcessBean.java 

모든 생성 된 클래스 파일은 패키지 전용 폴더에 저장됩니다. 이 전
는, 클래스 패스는 또한이 패키지 구조 내에 있지 오류 특정 클래스가 제거됩니다

classpath = %classpath%;. 

입니다 현재 폴더로 설정되어 있는지 확인합니다.

+0

도움이되었지만 질문이 하나 더있어 Ravinder, request.getParameter ("option")을 jsp \t \t \t \t \t $ {processBean.processRequest는 ('여기')} – user3331487

+0

이 ('processBean.processRequest (request.getParameter해야한다 "옵션"))'. –

+0

예제 @ [* JSP : useBean *] (http://www.coderanch.com/t/473342/JSP/java/jsp-useBean) –

0

컴파일러가 DBHandler를 찾으려면 컴파일러가 사용하는 클래스 경로에 있어야합니다.

게시물을 편집하여 명령 줄에서 컴파일했음을 나타내므로 "기본 디렉토리"(cd 대상 디렉토리)를 갖습니다. 디렉토리가 "projects"이므로 "packages"디렉토리가 있다고 가정 해 봅시다.

클래스 경로에 "projects"디렉토리가 있어야합니다. 명령 줄에 대한 기본 디렉토리를 프로젝트에서 컴파일하고 classpath에 "."을 포함 시키면됩니다. 당신은 클래스 패스에 "projects"디렉토리를 가질 수 있습니다.

Mac에서 시스템 변수를 설정하는 방법을 모르겠습니다. 다음과 같이 명령을 실행하여 명령 행에서 클래스 경로를 설정할 수 있습니다. javac -cp . helpers/ProcessBean.java

"." 기본적으로 클래스 경로에 있습니다. 나는 그걸 맥에 대해서도 모른다.

+0

OP에서 클래스 패스 문제가 발생하지 않는다고 생각합니다. – GingerHead

+0

죄송합니다. 혼란 스럽습니다. 메모장을 사용합니다. ++, Java를 처음 사용했습니다. – user3331487

+0

그래서 어떻게 컴파일합니까? 유닉스, 창문에 있니? 명령 줄을 사용합니까? 당신이하고있는 일에 관해서 우리가 아무것도 모르고 그런 식으로 질문을한다고 상상해보십시오. 컨텍스트 정보없이 질문이 무엇인지 파악할 수 있다고 가정하지 마십시오. – arcy

관련 문제