follow me on Twitter

    Subscribe to
    Posts [Atom]


    NoSuchProviderException: smtp

    Monday, December 29, 2008

    If you get the error:
    Caused by: javax.mail.NoSuchProviderException: smtp

    You most likely having a conflicting jar file. This happened to me when moving from my local machine to a Fedora Linux server. I updated the java version to Java 6. Java 6 already has java mail functionality found in the mail.jar file. Remove any jar files having to do with mail and your exception will go away.

    Labels: ,


    Linux MySQL Error

    Saturday, December 27, 2008

    if you try to use jdbc to connect to a MySQL database on a Linux distribution like Fedora or Redhat and get the error:

    java.sql.SQLException: Unexpected exception encountered during query.
    Caused by: java.io.CharConversionException

    Solution:
    modify /etc/my.cnf add the line:
    default-character-set=utf8

    You can also use a more recent version of java.

    Labels:


    How to install and connect from a client to MySQL on Fedora

    Wednesday, December 24, 2008

    1. Install the rpm via yum with the following command: yum -y install mysql mysql-server
    2. assign passwords to default accounts like this:
    2a. switch to root account with: (usr/local/mysql/bin) mysql -u root
    mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
    mysql> SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');
    You can see the reference here.
    3. Create a database with the command: CREATE DATABASE dbname;
    4. If you would like to connect from a client you must enter a row in the "user" table like this:
    insert into mysql.user(Host, User) values ('192.168.1.2','root');
    4a. You can also check if your desired host already exists in the user table by first switching to the root account and then issuing the query: SELECT Host, User FROM mysql.user;
    5. You now need to grant permissions with the command: GRANT ALL PRIVILEGES ON *.* TO 'user'@'host' IDENTIFIED BY 'password' WITH GRANT OPTION;
    5a. restart mysql with the command (as root): service mysqld restart
    6. Tadah!!!!! You're running MySQL on Fedora and connecting to your new database from a client!!!

    Labels:


    MySQL Magic

    Monday, December 22, 2008

    How to login with the mysql user: sudo bin/mysqld_safe --user=mysql --log &
    Shutdown mysql server: bin/mysqladmin -u root shutdown
    switch to root user: bin/mysql -u root
    initialize context for a database: USE databasename or mysql -h host -u user -p dbname

    MySQL Commands


    Create A Table
    CREATE TABLE `joetest`.`User` (
    `id` INT( 255 ) NOT NULL AUTO_INCREMENT,
    `user_name` VARCHAR( 20 ) NOT NULL ,
    `password` VARCHAR( 20 ) NOT NULL ,
    PRIMARY KEY ( `id` )
    ) ENGINE = INNODB

    Labels:


    Reading a file from a local directory into a byte array

    Wednesday, December 17, 2008

    This can be done with the following code:

    public static byte[] getBytesFromFile(File file) throws IOException {
    InputStream is = new FileInputStream(file);

    // Get the size of the file
    long length = file.length();

    if (length > Integer.MAX_VALUE) {
    // File is too large
    }

    // Create the byte array to hold the data
    byte[] bytes = new byte[(int)length];

    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length
    && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
    offset += numRead;
    }

    // Ensure all the bytes have been read in
    if (offset < bytes.length) {
    throw new IOException("Could not completely read file "+file.getName());
    }

    // Close the input stream and return bytes
    is.close();
    return bytes;
    }

    Labels: