Hello, I am trying to create a method that returns me% String[]
with the data from 2 different tables in this case is the table user
and the table geolocation
, the data of the user with its respective geolocation (city , neighborhood, latitude, longitude.
But I can not create a "correct" query.
static String[] getUserDataFromDb(JTextField id, JPasswordField pass) throws SQLException {
String[] data = new String[9];
Connection c = connectDB();
Statement stmt = null;
String query1 = "SELECT * FROM users INNER JOIN geolocation ON user.userid = geolocation.userid" ;
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(query1);
while (rs.next()) {
data[0] = rs.getString("userid").trim();
data[1] = rs.getString("name").trim();
data[2] = rs.getString("surname").trim();
data[3] = rs.getString("email").trim();
data[4] = rs.getString("password").trim();
data[5] = rs.getString("city").trim();
data[6] = rs.getString("district").trim();
data[7] = rs.getString("latitude").trim();
data[8] = rs.getString("longitudes").trim();
}
stmt.close();
c.close();
return data;
}
It always returns a error
since the query is not well written.
The tables are:
users:
+-------+-------------+------+-----+---------------------+
| name | surname | email |password|userid|
+-------+-------------+------+-----+---------------------+
| jose | aguilar | [email protected] | 123 |jose23|
+-------+-------------+------+-----+---------------------+
geolocation:
+-----------+-------------+-----------+---------+----------+
| city | district | latitude |longitude| userid |
+-------+-------------+-------------------------+----------+
| su ciudad | su barrio | 1.2 | -1.3 | jose23 |
+-----------+-------------+-----------+---------+----------+