How to change the datatype from varchar to int using JDBC connection with Java of a table in MySQL?
I tried to use the query:
Alter table table_name CHANGE 'col 1' 'col 1' int (5 );
The file I am importing using the import option has the values in varchar, but I only required integer values from that table. The values of the imported table are not in ordered but the integer values are useful for me.
When I used the alter query in the phpmyadmin it works absolutely fine, but when I tried to alter in jdbc it gives me the error:
Incorrect integer value: at 'col 1';
jdbc code was as:
try {
Connection co=DriverManager.getConnection("jdbc:mysql://localhost:3306/csv_db","root",null);
String c= " ALTER TABLE tpf1 MODIFY `col 3` int(5)";
String t="Alter table table_name CHANGE 'col 1' 'col 1' int (5 );";
Statement stmt=co.createStatement();
stmt.executeUpdate(t);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex);
}
Edit
try {
Connection co=DriverManager.getConnection("jdbc:mysql://localhost:3306/csv_db","root",null);
String c= " ALTER TABLE tpf1 MODIFY `col ` int(20)";
Statement stmt=co.createStatement();
stmt.executeUpdate(t);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex);
}
The table screenshot is in the Photo:
This is actually a pdf file and converted it into .csv and imported to my database And i only need integer values from the table not any other alphabets and symbol. This code is only for one column and i need to alter all the three columns.So what should i do to get only integer values using jdbc? :| :)
'col 1', you need to use`col 1`, although it might as well mean thatcol 1contains a value that is not convertible to an integer value.[col 1]right @MarkRotteveel