Skip to content

Is the JAR file missing as I couldn't see the mysql-connectot-java.jar do we need one to connect to mysql database #10

Description

@adetheprince

I am totally new and I am a bit confused about the JAR file that every tutorial mentioned.
I can see you have a java class Constants that you inserted link to jsp files.
I have uploaded all these file to my ubuntu server where mysql installed, I have changed the mysql address from "jdbc:mysql://localhost/facebookandroid?user=root&password=test123" to mine example "jdbc:mysql://localhost/facebookandroid?user=root&password=mypassword" on every jsp but I am not able to connect or insert any data to my database, I have tested the register page to no availe, not sure where I am wrong, I am also sure the database called facebookandroid does exist and mysql is started and running, I also have user called root with password mypassword, after tested the file with android studio I get the actual jsp file code printed out on the screen as its an error toast , strange that I cant see any error in AS log, here is the image can you please help me or guide me where I am going wrong.

`<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql."%>
<%@page import="org.json.
" %>

<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/facebookandroid?user=root&password=adilimaam");
PreparedStatement statement = con.prepareStatement("select * from users where userEmail=?");
statement.setString(1, request.getParameter("userEmail"));
ResultSet rs = statement.executeQuery();
if(rs.next()){
response.getWriter().append("error");
} else {
PreparedStatement statement1 = con.prepareStatement("insert into users(userName,userEmail,userPassword) values(?,?,?)");
statement1.setString(1, request.getParameter("userName"));
statement1.setString(2, request.getParameter("userEmail"));
statement1.setString(3, request.getParameter("userPassword"));
statement1.executeUpdate();
response.getWriter().append("okay");
}
con.close();
%>

<%!
public static void convertResultSetIntoJSON(ResultSet resultSet, HttpServletResponse response) throws Exception {
JSONArray jsonArray = new JSONArray();
while (resultSet.next()) {
int total_rows = resultSet.getMetaData().getColumnCount();
JSONObject obj = new JSONObject();
for (int i = 0; i < total_rows; i++) {
String columnName = resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase();
Object columnValue = resultSet.getObject(i + 1);
// if value in DB is null, then we set it to default value
if (columnValue == null){
columnValue = "null";
}
/*
Next if block is a hack. In case when in db we have values like price and price1 there's a bug in jdbc -
both this names are getting stored as price in ResulSet. Therefore when we store second column value,
we overwrite original value of price. To avoid that, i simply add 1 to be consistent with DB.
*/
if (obj.has(columnName)){
columnName += "1";
}
obj.put(columnName, columnValue);
}
jsonArray.put(obj);
}
response.getWriter().write(jsonArray.toString());
}
%>
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions