我正在使用JPA(EclipseLink實現)在Google Cloud SQL之上構建Google Cloud Endpoints API。 當我通過該API插入非ASCII字符(即希伯來語或阿拉伯語)字符串時,它在Google App Engine上部署的應用程序中正常工作,但在本地Java Development Server上,這些字符保存爲'?'。 當我使用「常規」servlet訪問相同的數據庫表並插入相同的字符串(通過DriverManager.getConnection()獲取數據庫連接)時,一切正常,因此它不會成爲本地數據庫設置的問題。非ASCII字符保存爲'?'在Google App Engine開發環境中使用JPA
我使用(無論是對servlet和基於JPA實現)「com.mysql.jdbc.Driver」我的連接網址是
"jdbc:mysql://127.0.0.1:3306/guestbook?user=root&useUnicode=true&characterEncoding=UTF-8"
我有我的AppEngine-web.xml中有以下條目文件:
<property name="file.encoding" value="UTF-8" />
<property name="DEFAULT_ENCODING" value="UTF-8" />
並且character_set_server和character_set_database在本地服務器上都設置爲utf8。
這裏是我的插入字符串到數據庫代碼:
public class Guestbook {
private static Map<String, String> properties;
private static EntityManagerFactory emf;
static{
properties = new HashMap();
properties.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.Driver");
properties.put("javax.persistence.jdbc.url",
"jdbc:mysql://127.0.0.1:3306/guestbook?user=root&useUnicode=true&characterEncoding=UTF-8");
emf = Persistence.createEntityManagerFactory(
"Demo", properties);
}
@ApiMethod(name = "greetings.insert", httpMethod = "post")
public void insertEntry(GuestEntry entry) {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(new GuestEntry(entry.getMessage()));
em.getTransaction().commit();
em.close();
}
}
沒有人有任何線索?
在你的mysql連接url中有一個缺失的問號:打字錯誤? –
是這裏的錯字 - 修復了它 – Boaz