Link to home
Start Free TrialLog in
Avatar of jvilla1983
jvilla1983

asked on

MYSQL/JAVA.. Data too long for column 'HOSTNAME' at row 1

Hi,

I keep getting the error..

Exception in thread "main" java.sql.SQLException: Data too long for column 'HOSTNAME' at row 1

even when I set my VARCHAR(50) and I know that I don't need THAT many characters. I was thinking it was because I had periods in the string, but that shouldn't matter should it?

Thanks in advance..

Here are my errors..

Exception in thread "main" java.sql.SQLException: Data too long for column 'HOSTNAME' at row 1
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)
        at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1225)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2278)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2225)
        at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1259)
        at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1205)
        at javaapplication6.PingDB.pushDatabase(PingDB.java:88)
        at javaapplication6.PingDB.generateDatabase(PingDB.java:44)
        at javaapplication6.Main.main(Main.java:33)
Java Result: 1
BUILD SUCCESSFUL (total time: 42 seconds)


System.out.println(ComputerList.get(i).getHOSTNAME());
                //Insert the record.
                String pushNonExistant = "INSERT INTO pingresults VALUES('"  + ComputerList.get(i).getIP_ADDR() +"','" +
                ComputerList.get(i).getHOSTNAME() + "','" + ComputerList.get(i).getIS_ALIVE_String() + "','" +
                ComputerList.get(i).getDATE()+ "')";
 
                //This will run a push statement on to the database we select...
                stmt.executeUpdate(pushNonExistant);

Open in new window

Avatar of jvilla1983
jvilla1983

ASKER

Oh.. one minor note.. I'm using JDBC.
Avatar of Mick Barry
thats because your hostname is too long. check the hostname isn't padded

whats this display:

System.out.println(ComputerList.get(i).getHOSTNAME().length());

See, I did that.. and thought that might be the issue.. but I have VARCHAR(50) and it's just a little over 20 characters..

I apologize I can't give out the exact name of the server, but.. the structure is like this.

nameofserver.xx.yyyy.zzz
use the code i posted above to print exactly how long it is.

also make sure you have the columns in the correct order. Explicitly specify the column names is a better practice.


22
ok.. Something isn't right here..

I deleted the tables and then tried the program again and it's still acting as if there is a table, when there shouldn't be.

It's also referring to a table name I used earlier today which I changed a while back when I created the table.
check your connection string

Exception in thread "main" java.sql.SQLException: Data too long for column 'HOSTNAME' at row 1
I'm still getting this when there isn't a table to query!!
and... I just dropped the database and it's still trying to query it! It's acting as if MYSQL is still providing it with a connection to that database and remembering the table I deleted.
My connection string is connecting to my MYSQL server. I know it works because I logged into my server and shut down MySQL. It didn't see the server then...

But when I turned it back on, it was the same thing going on.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DUDE.. YOU ARE A LIFESAVER!! you know how long I've been trying to get this D^@$ Database to work!!!

HAHAHA!!! Looks like I might be able to get some sleep tonight!

Tthanks a bunch!!