数据库是openshift空间的MySQL用jdbc连接host:127.3.57.130port:3306user:adminUDd3gqapassword:ZcbM-TbtK7yZ我用navicat成功连接了数据库,IDPWD决对没问题(navicat是单独连接服务器...
数据库是openshift空间的MySQL 用jdbc连接
host:127.3.57.130
port:3306
user:adminUDd3gqa
password:ZcbM-TbtK7yZ
我用navicat成功连接了数据库,ID PWD决对没问题(navicat是单独连接服务器mysql的软件)
以下是代码
String
user="adminUDd3gqa";
String
pass="ZcbM-TbtK7yZ";
String
url = "jdbc:mysql://127.3.57.130:3306/8158" ;
try {
Class.forName(
"com.mysql.jdbc.Driver");
Connection
m_connection = DriverManager.getConnection(url, user , pass);
}
catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.
out.print("jdbc..........................erro");
}
异常出在m_connection = DriverManager.getConnection(url, user , pass);
还有在openshift贴吧里的人是配制tomcat的context.xml 用ServletContextEvent的各种方法获得用户信息,知道的解释下(贴吧是英文的看不懂)
driver
com.mysql.jdbc.Driver
url
jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/burgerjoint
user
admin******
password
*********
public void contextInitialized(ServletContextEvent event) {
// Connect
String driver = event.getServletContext().getInitParameter(PARAM_DRIVER);
String url = event.getServletContext().getInitParameter(PARAM_URL);
String username = event.getServletContext().getInitParameter(PARAM_USERNAME);
String password = event.getServletContext()
.getInitParameter(PARAM_PASSWORD);
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username,
password);
event.getServletContext().setAttribute(ATTR_CONNECTION, connection);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
我用普通项目也连不上,谁帮我测试下。。。。
展开