🔒 Closed Java Unexpected Type assigning string error

Status
Not open for further replies.

SUNRAI

Eternal Poster
Error in String p = id_col + " " = first_name + last_name + " " + job; line

package database_console; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.sql.ResultSet; public class DBConnect { public static void main(String[] args) { try { String host = "jdbc:derby://localhost:1527/Employees"; String uName = "songalia"; String uPass = "relente1"; Connection con = DriverManager.getConnection(host, uName, uPass); Statement stmt = con.createStatement(); String sql = "SELECT * FROM Workers"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int id_col = rs.getInt("ID"); String first_name = rs.getString("First_Name"); String last_name = rs.getString("Last_Name"); String job = rs.getString("Job_Title"); String p = id_col + " " = first_name + last_name + " " + job; System.out.println(p); } } catch( SQLException err) { System.out.println( err.getMessage()); } } }
 
The error in the code is on this line:

Code:
String p = id_col + " " = first_name + last_name + " " + job;

The equal sign (=) should be a plus sign (+). The corrected line should look like this:

Code:
String p = id_col + " " + first_name + last_name + " " + job;

This will concatenate the id_col, first_name, last_name, and job variables with spaces in between and store the result in the p variable.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 505
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,130
Guests online
1,345
Total visitors
2,475

Forum statistics

Threads
2,273,513
Posts
28,950,052
Members
1,235,788
Latest member
ZaynAaqil28
Back
Top