Java:208:error:cannot find symbol

5 posts / 0 new
Last post
Offline
Last seen: 4 years 1 month ago
Joined: 05/15/2019
Posts: 10
Java:208:error:cannot find symbol

I'm currently faced with this problem. Can anyone advise on how to solve this problem?

** I'm working on the RTI JAVA (Hello_world) with mySQL database.

Offline
Last seen: 3 years 5 months ago
Joined: 08/20/2012
Posts: 25

The examples as shipped don't contain this line, so I am assuming that you are modifying the example to make use of MySQL. I suspect you need to call the prepareStatement() method on the Connection object. However, I wanted to make sure you are aware that RTI offers an off-the-shelf Database Integration Service with bidirectional integration; samples received can be stored in tables, and data inserted into tables can be published in Topics.

Regards,
Tom

Offline
Last seen: 4 years 1 month ago
Joined: 05/15/2019
Posts: 10

Yes I'm modifying the example with the help of MySQL. I have inserted the following into my program and the result is as shown in the pic(above). Not sure if the code below is the correct way to write it. (I'm using Visual Studio Code to write the Java example program of "Hello_World").

Class.forName("com.mysql.jdbc.Driver");
System.out.print("Connecting to database");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "userid", "pass");
Statement st = conn.createStatement();
 
try {
String sql = "INSERT INTO anexample(ID,Temp) VALUES (?,?)";
PreparedStatement ps = Connection.PreparedStatement(sql);
ps.setInt(1, id);
ps.setFloat(2, temp);
ps.executeUpdate();
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
Offline
Last seen: 3 years 5 months ago
Joined: 08/20/2012
Posts: 25

I hoped you might try my previous suggestion on the syntax: PreparedStatement(sql) --> prepareStatement(sql). Also, have you looked at Database Integration Service and concluded it doesn't suit your use case?

Offline
Last seen: 3 years 6 months ago
Joined: 09/11/2020
Posts: 1

Your code appears to be referring to something that the compiler doesn't understand. When your code is compiled, the compiler needs to work out what each and every identifier in your code means. As the compiler is going through the code it will find something and know what to do with it or not. The general causes for a Cannot find symbol error are things like:

  • Incorrect spelling.
  • Wrong case. Halo is different from halo.
  • Improper use of acceptable identifier values (letters, numbers, underscore, dollar sign), my-class is not the same as myclass.
  • No variable declaration or variable is outside of the scope you are referencing it in.