Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm developing the solution that you're asking for. I've added to my build path in eclipse two library:</p> <p>mysql-connector-java-5.1.18-bin.jar (for MySQL) <a href="http://www.mysql.it/downloads/connector/j/" rel="nofollow">http://www.mysql.it/downloads/connector/j/</a></p> <p>jtds-1.3.0.jar (for MSSQL) <a href="http://jtds.sourceforge.net/" rel="nofollow">http://jtds.sourceforge.net/</a></p> <p>If you use Eclipse it's a good idea download SQL Explorer and try the connection under that. The string that you must use for the connections are:</p> <pre><code> String url="jdbc:jtds:sqlserver://IP-SERVER:1433/DB"; String url2="jdbc:mysql://IP-SERVER:3306/DB"; </code></pre> <p>Before than you must pay attention that MySQL and MSSQL accept external connection if you aren't under localhost. For MySQL you must modify in the configuration file the parameter bind that have 127.0.0.1 as default value, change it in 0.0.0.0 (not secure) or with a list of allowed IP. For MSSQL you must be sure that TCP-IP it's enabled and that the defaults ports are 1433.</p> <p>In java you can easily open two different connection and copy records between different DB. It's a good idea if the data are big use the PreparedStatement that improve the performance if you, for example, need to copy from MSSQL local to MySQL remote. Here a piece of code without exception handler that I've removed for make a message more short.</p> <pre><code>import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; java.sql.Statement s; java.sql.ResultSet rs; java.sql.Statement s2; java.sql.ResultSet rs2; java.sql.PreparedStatement psmtMySQL; con = DriverManager.getConnection(url, id, pass); con2 = DriverManager.getConnection(url2, id2, pass2); if(con!=null &amp;&amp; con2!=null){ try{ s = con.createStatement(); rs = s.executeQuery(sql); sql ="INSERT INTO TABLE (FIELD1, FIELD2, FIELD3) " + "VALUES (?,?,?);"; con2.setAutoCommit(false); psmtMySQL = con2.prepareStatement(sql); con2.setAutoCommit(true); while( rs.next() ){ try { psmtMySQL.setLong(1, rs.getLong("Field1")); psmtMySQL.setLong(2, rs.getLong("Field2")); psmtMySQL.setString(3, rs.getString("Field3")); psmtMySQL.addBatch() ; } catch (SQLException sqle){ sqle.printStackTrace(); } } psmtMySQL.executeBatch(); con2.setAutoCommit(true); psmtMySQL.close(); rs2.close(); s2.close(); conn2.close(); rs.close(); s.close(); conn.close(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload