Hi All, 

I am trying to store the data in mysql database for TestSerial application, but 
when I run my application, I get bunch of errors,

Here is what I get as errors:

Sending packet 0
ClassNotFoundException: com.mysql.jdbc.Driver
SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test
Exception thrown when sending packets. Exiting.
java.lang.NullPointerException


Here is my code:

import java.io.IOException;
import net.tinyos.message.*;
import net.tinyos.packet.*;
import net.tinyos.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;

public class TestSerial implements MessageListener {

  private MoteIF moteIF;
  
  public TestSerial(MoteIF moteIF) {
    this.moteIF = moteIF;
    this.moteIF.registerListener(new TestSerialMsg(), this);
  }


static String userid="root", password="ashokkumar";

static String url = "jdbc:mysql://localhost:3306/test";
static Connection con = null;
static Statement stmt = null;
private PreparedStatement preparedStatement = null;
 

public static Connection getJDBCConnection(){
        try {

        Class.forName("com.mysql.jdbc.Driver");

        } catch(java.lang.ClassNotFoundException e) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(e.getMessage());
        }

        try {
        con = DriverManager.getConnection(url, userid, password);
        } catch(SQLException ex) {

        System.err.println("SQLException: " + ex.getMessage());
        }
        return con;
}
public void sendPackets() {
    int counter = 0;
    TestSerialMsg payload = new TestSerialMsg();
    
    try {
      while (true) {
        System.out.println("Sending packet " + counter);
        Connection con = getJDBCConnection();
        preparedStatement = con.prepareStatement("insert into 
test.TestSerialData (counter,dummyName) values (?,?)");
        preparedStatement.setString(1,Integer.toString(counter));
        preparedStatement.setString(2,"Jenis");
        preparedStatement.executeUpdate();
        con.close();

        payload.set_counter(counter);
        moteIF.send(0, payload);
        counter++;
        try {Thread.sleep(1000);}
        catch (InterruptedException exception) {}
      }
    }
    catch (Exception exception) {
      System.err.println("Exception thrown when sending packets. Exiting.");
      System.err.println(exception);
    }
  }

  public void messageReceived(int to, Message message) {
    TestSerialMsg msg = (TestSerialMsg)message;
    System.out.println("Received packet sequence number " + msg.get_counter());
  }
  
  private static void usage() {
    System.err.println("usage: TestSerial [-comm <source>]");
  }
  
  public static void main(String[] args) throws Exception {
    String source = null;
    if (args.length == 2) {
      if (!args[0].equals("-comm")) {
        usage();
        System.exit(1);
      }
      source = args[1];
    }
    else if (args.length != 0) {
      usage();
      System.exit(1);
    }
    
    PhoenixSource phoenix;
    
    if (source == null) {
      phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
    }
    else {
      phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
    }

    MoteIF mif = new MoteIF(phoenix);
    TestSerial serial = new TestSerial(mif);
    serial.sendPackets();
  }


} 


I have copied mysql-connector jar in TestSerial folder as well as 
/tinyos/support/sdk/java/ folder. In the later folder, I have even extracted 
the jar file. I am not able to understand why I am getting this error. Please 
help.

Thanks.
Jenis


_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to