2012-04-20 3 views
1

Java Server Faces 및 JavaDB를 처음 사용했습니다. 나는 "스키마 'ROOT'존재하지 않는 오류로 인해 내 데이터베이스로 인해 연결하는 데 어려움을 겪고 있습니다. 나는 이걸로 내 머리카락을 꺼내고있어 그리고 그것은 뭔가 간단해야합니다 알아요. 데이터베이스 "guest_book"에 대한 사용자 이름이나 비밀번호를 설정하지 않았습니다. 데이터베이스는 APP 스키마 아래에 있습니다. 다음과 같이 관리 BeanJavaDB 오류 'Schema'ROOT 'does not exist'

package com.jsf; 

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 

import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import javax.annotation.Resource; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.sql.DataSource; 
import javax.sql.rowset.CachedRowSet; 

/** 
* 
* @author pctdeveloper7 
*/ 
@ManagedBean(name="guestbean") 
@SessionScoped 
public class GuestBookBean { 

private String date; 
private String fname; 
private String lname; 
private String email; 
private String message; 

@Resource(name="jdbc/guest_book") 
DataSource ds; 

/** 
* Creates a new instance of NewJSFManagedBean 
*/ 
public GuestBookBean() { 

} 

public String getDate() { 
    return date; 
} 

public void setDate(String date) { 
    this.date = date; 
} 

public String getEmail() { 
    return email; 
} 

public void setEmail(String email) { 
    this.email = email; 
} 

public String getMessage() { 
    return message; 
} 

public void setMessage(String message) { 
    this.message = message; 
} 

public String getFname() { 
    return fname; 
} 

public void setFname(String fname) { 
    this.fname = fname; 
} 

public String getLname() { 
    return lname; 
} 

public void setLname(String lname) { 
    this.lname = lname; 
} 



//return a resultset of entries 
public ResultSet getEntries() throws SQLException{ 
    //Check if was injected by the server 
    if(ds == null) 
     throw new SQLException("Unable to obtain datsource"); 

    //get connection from datapool 
    Connection conn = ds.getConnection("root","root"); 

    //check if connection was successful 
    if(conn==null) 
     throw new SQLException("Unable to connect to DataSource"); 



    try{ 

     //Create a prepared statement to insert a new address book entry 
     PreparedStatement getMessages = conn.prepareStatement("Select * " + 
       "FROM MESSAGES ORDER BY lname, fname"); 
     CachedRowSet rowset= new com.sun.rowset.CachedRowSetImpl(); 
     rowset.populate(getMessages.executeQuery()); 
     return rowset; 
    } finally{ 
     conn.close(); //return connection to pool 
    } 
}//End getEntries 

//Save a new guestbook message 
public String save() throws SQLException{ 

    //Check if was injected by the server 
    if(ds == null) 
     throw new SQLException("Unable to obtain datsource"); 

    //get connection from datapool 
    Connection conn = ds.getConnection(); 

    //check if connection was successful 
    if(conn==null) 
     throw new SQLException("Unable to connect to DataSource"); 

    try{ 
     //create a preparedStatement to insert a new guestbook entry 
     PreparedStatement insertEntry = conn.prepareStatement("INSERT INTO"+ 
       "messages values(?, ?, ?, ?, ?)"); 
     //define prepared statements arguements 
     insertEntry.setString(1, fname); 
     insertEntry.setString(2, lname); 
     insertEntry.setString(3, email); 
     insertEntry.setString(4, message); 
     insertEntry.setString(5, date); 

     insertEntry.executeUpdate();// insert the new entry 
     return "index"; //go back to the index page 

    }finally{ 
     conn.close();//return connection to the pool 
    } 
}//END Save() 

}

다음과 같이 데이터베이스가 생성하는 데 사용되는 SQL을 ..

create table messages 
(
    fname varchar(25), 
    lname varchar(35), 
    email varchar(50), 
    message varchar(300), 
    "DATE" varchar(11) 
); 

Insert into messages 
values('Jared', 'Rainey', '[email protected]', 'Hi!', '10-12-1982'); 

연결 풀 GuestBookPool 이름 .. 코딩 및 데이터 소스입니다 jdbc/guest_book. 나는 암호 나 사용자 이름을 아무 것도 설정하지 않았으며 모두 APP 스키마에 따라 내가 이해 한 것으로부터 만들어졌습니다. 어떤 도움이라도 대단히 감사하겠습니다!

+0

데이터 소스를 어떻게 구성합니까? –

답변

-1

JSF를 사용하는 경우 프로젝트에 표시된 Web-INF 폴더에 ApplicationContext를 작성하여 데이터베이스에 연결할 수 있습니다.

원하는 데이터 소스의 싱글 톤 빈을 만듭니다.

사용중인 방법이 선호되지 않습니다.

좀 더 도움을 받으려면 사용중인 데이터베이스를 물어봐도 될까요? 오라클, 포스트 그레스, 액세스 등?

+1

빈 클래스에서 데이터 소스를 선언하는 것은 바람직하지 않습니다. – abhi

+0

질문 제목에 명시된 바와 같이, OP는 JavaDB를 사용합니다. –

0

@ManagedBean(name="guestbean"); 대신 @ManagedBean(name="guestbean", schema="APP"); 또는 스키마가 무엇이든 시도하십시오.

관련 문제