【发布时间】:2016-02-04 02:17:45
【问题描述】:
这是注册到网站的jsp的一部分,它将用户在另一个html中插入的数据放入一个mysql数据库中......在本地一切正常,但是当我上传网站时到 Openshift,它给出了 String matot 和 cittatot 的错误:方法 join(String, String[]) is undefined for the type String
我也不太确定连接字符串是否正确,哈哈
有人可以温柔地帮助我吗?
<%@ page import ="java.sql.*" %>
<%
String pass = request.getParameter("pass");
String email = request.getParameter("email");
String surname = request.getParameter("surname");
String[] citta = request.getParameterValues("citta");
String name = request.getParameter("name");
String titolo = request.getParameter("titolo");
String numero = request.getParameter("numero");
String prezzo = request.getParameter("prezzo");
String info = request.getParameter("info");
String[] materia = request.getParameterValues("materia");
String matot = String.join(",",materia);
String cittatot = String.join(",",citta);
Class.forName("com.mysql.jdbc.Driver");
String host = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
String port = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
String username = System.getenv("OPENSHIFT_MYSQL_DB_USERNAME");
String password = System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD");
String url = String.format(":mysql://%s:%s/easylesson", host, port);
Connection con = DriverManager.getConnection(url, username, password);
Statement st = con.createStatement();
//ResultSet rs;
int var = st.executeUpdate(" insert into iscritti(email,pass,datareg,titolo,numero,prezzo,info,cittatot,matot,name,surname) values ('" + email + "','" + pass + "', CURDATE(),'" + titolo + "','" + numero+ "','" + prezzo+ "','" + info+ "','" + cittatot+ "','" + matot + "','" + name + "','" + surname+ "')");
【问题讨论】:
-
Java 8 支持静态方法 String.join,但以前的 Java 版本不支持。 Openshift 必须使用早于 8 的版本...顺便说一下,您的连接字符串应如下所示:“jdbc:mysql://localhost:3306/myschema”。
-
我使用 StringUtils.join 方法解决了连接问题。但是连接字符串中仍然存在错误...我认为您编写的只是用于本地数据库。我正在使用 phpmy 管理插件,数据库在 openshift 服务器上
-
编辑:也解决了连接问题!
标签: java mysql string tomcat openshift