[jdbc] erreur : com.mysql.jdbc.MysqlDataTruncation
Bonjour,
J'ai de gros problème pour insérer une nouvelle ligne dans ma base de données MySql. Je travaille sous Ubuntu Breezy, Eclipse, j'ai connector J 3.1.13.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| package testConnectorJ;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DataBase
{
Connection con;
// ----------------------------
String dbUrl = "jdbc:mysql://localhost/InformationPanneau";
String user = "tvbuilder";
String password = pass
public DataBase ( )
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch ( Exception e )
{
}
}
// ------------------------------------------------------
public void open ( )
{
try
{
con = DriverManager.getConnection(dbUrl, user, password);
}
catch ( SQLException e )
{
}
}
// -----------------
public void close ( )
{
try
{
con.close( );
}
catch ( Exception e )
{
System.out.println( "echec lors de la fermeture:" + e.getMessage( ) );
}
}
public PreparedStatement prepareStatement(String sql)
{
PreparedStatement ps = null;
try
{
ps = (PreparedStatement) con.prepareStatement(sql);
}
catch ( SQLException e )
{
}
return ps;
}
} |
seconde classe :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| package testConnectorJ;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class SqlManager
{
// DataBase db;
private DataBase db;
// CONSTRUCTOR //
public SqlManager ( )
{
db = new DataBase( );
}
// PUBLIC METHODS //
public void insertNewAuthor ( int login )
{
db.open( );
String sqlInsert = "INSERT INTO Author ( authorCreat , authorModif , isVisible ) VALUES (?,?,?)";
PreparedStatement ps = db.prepareStatement( sqlInsert );
try
{
ps.setInt( 1, login );
ps.setNull( 2, 0);
ps.setString( 3, "true" );
ps.executeUpdate( );
}
catch ( SQLException e )
{
System.out.println( "SqlManager :: insertNewAuthor :: " + e.toString( ) );
}
finally {
db.close();
}
}
} |
et dans une dernière classe, on appelle l'objet ms = new SqlManager();
et j'obtiens l'erreur :
Citation:
SqlManager :: insertNewAuthor :: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data truncated for column 'isVisible' at row 1
or voici ma table :
Code:
1 2 3 4
| id int(11) auto_increment
authorCreat int(11)
authorModif int(11)
isVisible enum('true', 'false') |
Des idées ? Là, je sèche lamentablement.