Witam,
Mam nastepujacy problem:
Chce zaimportowac dane z pliku temp.txt do bazy utworzonej w mysql. W przypadku zadeklarowania tabeli w bazie jako integer program dziala(oczywiscie obcina .2) Natomiast jesli deklaruje tabele jako real lub float
wyrzuca blad:
java.sql.SQLException: Data truncated for column 'price' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485)
at automateimport.DBase.importData(automateImport.java:75)
at automateimport.automateImport.main(automateImport.java:26)
zawartosc temp.txt
tomek 1111
romek 2.2
struktura bazy:
CREATE TABLE testtable
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
text varchar(45) NOT NULL,
price float not null);
kod programu:
package automateimport;
/**
*
-
@Author Tomek
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class automateImport
{
public static void main(String[] args)
{
DBase db = new DBase();
String filename = "c:/temp.txt";
Connection conn = db.connect(
"jdbc//localhost:3306/test","root","root");
db.importData(conn,filename);
}
}
class DBase
{
public DBase()
{
}
public Connection connect(String db_connect_str,
String db_userid, String db_password)
{
Connection conn;
try
{
Class.forName(
"com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(db_connect_str,
db_userid, db_password);
}
catch(Exception e)
{
e.printStackTrace();
conn = null;
}
return conn;
}
public void importData(Connection conn,String filename)
{
Statement stmt;
String query;
try
{
stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
query = "LOAD DATA INFILE '"+filename+
"' INTO TABLE testtable (text,price);";
stmt.executeUpdate(query);
}
catch(Exception e)
{
e.printStackTrace();
stmt = null;
}
}
}
Prosze o pomoc.