Opa!
Quero copiar uma tabela Postgre no MySQL, mas dá o seguinte erro:
java.sql.SQLException: Column count doesn’t match value count at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3004)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1128)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1357)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1274)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1259)
at copia.main(copia.java:26)
Abaixo vai o código que estou usando. Se alguém puder ajudar, agradeço fortemente.
import java.sql.*;
public class copia {
public static void main(String args[]) {
Connection con1;
Connection con2;
String query1 = “select * from fut where pais = ‘Albania’”;
Statement state1;
PreparedStatement ps;
int i;
int linhas;
try {
Class.forName(“org.postgresql.Driver”);
con1 = DriverManager.getConnection(“jdbc:postgresql://localhost/postgres”, “postgres”, “peposa”);
state1 = con1.createStatement();
ResultSet rs = state1.executeQuery(query1);
ResultSetMetaData rsmd = rs.getMetaData();
Class.forName(“com.mysql.jdbc.Driver”);
con2 = DriverManager.getConnection(“jdbc:mysql://localhost/futebol”, “root”, “peposa”);
int cont = rsmd.getColumnCount();
while (rs.next()) {
for (i = 1; i <= cont; i++) {
System.out.print(rs.getString(i));
}
String query2 = “insert into fut values(” + i + “)”;
ps = con2.prepareStatement(query2);
linhas = ps.executeUpdate();
}
state1.close();
con1.close();
con2.close();
}
catch (ClassNotFoundException e) {
System.out.println(“Driver perdido”);
}
catch (SQLException ex) {
System.out.println(“Query perdida”);
ex.printStackTrace();
}
}
}