mySql error with Ethernet shield 2

hi
when i tried to verify the example of mySql using an Ethernet shield 2, and after i changed the library to <Ethernet2.h> , it showd error in the compiler , even thought i did not change any thing else, plz help :cry:

Please post your current IP address, the password to your router, what operating system you are using, and any passwords needed to get into your computer so that one of us might hack into your system and take a look at the offending code. Or you could just post the code here. But I don't see how anyone here is going to be able to tell you anything about that code without being able to actually see it.

Here u go :

#include <SPI.h>
#include <Ethernet2.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(10,0,1,35);  // IP of the MySQL *server* here
char user[] = "root";              // MySQL user login username
char password[] = "secret";        // MySQL user login password

// Sample query
char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";

EthernetClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
 Serial.begin(115200);
 while (!Serial); // wait for serial port to connect
 Ethernet.begin(mac_addr);
 Serial.println("Connecting...");
 if (conn.connect(server_addr, 3306, user, password)) {
   delay(1000);
 }
 else
   Serial.println("Connection failed.");
}


void loop() {
 delay(2000);

 Serial.println("Recording data.");

 // Initiate the query class instance
 MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
 // Execute the query
 cur_mem->execute(INSERT_SQL);
 // Note: since there are no results, we do not need to read any data
 // Deleting the cursor also frees up memory used
 delete cur_mem;
}

but the problem is, once i change the library to
#include //which is version one of the shield
its compiled properly ,
so i think the error is in the Ethernet2.h file

but the problem is, once i change the library to
#include //which is version one of the shield
its compiled properly ,
so i think the error is in the Ethernet2.h file

No, the problem is that when you changed, for some undefined reason, to the Ethernet2 library that you got from some undefined location, you got some error messages that you FAILED to post.

How can you reasonably expect us to help you when you provide so little information?

PaulS:
No, the problem is that when you changed, for some undefined reason, to the Ethernet2 library that you got from some undefined location, you got some error messages that you FAILED to post.

How can you reasonably expect us to help you when you provide so little information?

the Ethernet2.h library is used to Ethernet shield 2 officially from arduino

check : http://labs.arduino.org/Ethernet+2+Library

and the code that I've posted previously existed in arduino IDE as an example for mySql insert record program.

Maybe ask arduino.org ? Note that you posted this on arduino.cc. Who is 'official' is another question?

And if you want help, I strongly suggest that you post the error message (complete, not the last few lines).

In file included from C:\Users\alfar\Documents\Arduino\libraries\MySQL_Connector_Arduino\src/MySQL_Connection.h:37:0,
                 from fdsgsadf.ino:3:
C:\Users\alfar\Documents\Arduino\libraries\MySQL_Connector_Arduino\src/MySQL_Packet.h:36:22: fatal error: Ethernet.h: No such file or directory
 #include <Ethernet.h>
                      ^
compilation terminated.
Error compiling.

Your mysql_packet.h still includes Ethernet.h. I would change that to Ethernet2.h as well.

If you ever want to compile for the old shield, you need to change it back.

If you need to support both versions, you can modify the mysql libraries so they can handle both ethernet.h and ethernet2.h using #ifdef and modify your sketches as well.

Your main sketch could start with

#define NEWSHIELD

The libraries / sketches that need to use either ethernet.h or ehernet2.h can use something like below to include the correct library.

#include<Ethernet2.h>
#else
#include <Ethernet.h>
#endif

If you want to use ethernet.h, comment the line in the first code block out.

// Late edit: fixed missing close tag

sterretje:
Your mysql_packet.h still includes Ethernet.h. I would change that to Ethernet2.h as well.

If you ever want to compile for the old shield, you need to change it back.

If you need to support both versions, you can modify the mysql libraries so they can handle both ethernet.h and ethernet2.h using #ifdef and modify your sketches as well.

Your main sketch could start with

#define NEWSHIELD

The libraries / sketches that need to use either ethernet.h or ehernet2.h can use something like below to include the correct library.

#include<Ethernet2.h>

#else
#include <Ethernet.h>
#endif

[code]

If you want to use ethernet.h, comment the line in the first code block out.

i did't understand how is the code will be after ur changes, can you alter the code above to illustrate your method in handling this error ?

If you have to ask this, it might be safer to just modify the mysql library and change the include statement to use ethernet2.h

It's safer because any library that relies on ethernet.h will throw errors during compile time that you can fix in the above way.

sterretje:
Your mysql_packet.h still includes Ethernet.h. I would change that to Ethernet2.h as well.

If you ever want to compile for the old shield, you need to change it back.

If you need to support both versions, you can modify the mysql libraries so they can handle both ethernet.h and ethernet2.h using #ifdef and modify your sketches as well.

Your main sketch could start with

#define NEWSHIELD

The libraries / sketches that need to use either ethernet.h or ehernet2.h can use something like below to include the correct library.

#include<Ethernet2.h>

#else
#include <Ethernet.h>
#endif




If you want to use ethernet.h, comment the line in the first code block out.

// Late edit: fixed missing close tag

I don't think the library can see the #define from the sketch anyway unless it resides in the same folder with the sketch. In other IDEs maybe, but due to the way the Arduino IDE organizes files for the build process I think this will fail. At least I've never figured out how to make it work.

Delta_G:
I don't think the library can see the #define from the sketch anyway unless it resides in the same folder with the sketch. In other IDEs maybe, but due to the way the Arduino IDE organizes files for the build process I think this will fail. At least I've never figured out how to make it work.

OOPS :frowning: You more than likely are right.