Glassfish 4 / MySQL连接池无法正常工作

时间:2013-08-26 08:07:35

标签: mysql database jdbc glassfish database-connection

我试图设置derby和mysql数据库,但两次都找不到表。我创建了表,然后从网络上的不同设备连接到它。我只是无法使用连接池连接到它。

我收到以下消息“java.sql.SQLSyntaxErrorException:表/视图'USERS'不存在”或“表/视图'地址'不存在”的另一个例子。

我可以ping数据库,一切都在使用drivermanager工作,但它无法使用连接池。我的游泳池配置:

user:user
password:password
url:jdbc:mysql://localhost:3306/thechef
port:3306
DatabaseName:thechef
ServerName:localhost

这是我的档案:

Users.java

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

@ManagedBean
@SessionScoped  
public class Users {

private String userName;
private String firstName;
private String lastName;
private String city;
private String zipcode;
private String state;
private String country;
private String email;

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

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getZipcode() {
    return zipcode;
}

public void setZipcode(String zipcode) {
    this.zipcode = zipcode;
}

public String getState() {
    return state;
}

public void setState(String state) {
    this.state = state;
}

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

public String getEmail() {
    return email;
}

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

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}


public String save() throws SQLException
{
    if (ds==null)
        throw new SQLException ("unable to obtain datasource");

    Connection connection = ds.getConnection();

    if (connection==null)
        throw new SQLException ("unable to obtain datasource");

    try{
    PreparedStatement addEntry = connection.prepareStatement("INSERT INTO USERS (USERNAME, FIRSTNAME, LASTNAME)VALUES (?,?,?)");

    addEntry.setString(1, getUserName());
    addEntry.setString(2, getFirstName());
    addEntry.setString(3, getLastName());

    addEntry.executeUpdate();
    return "index";
    }

    finally{
    connection.close();
    }

}
}

0 个答案:

没有答案