Copy MS SQL Server table to SQLite table
up vote
2
down vote
favorite
A little background: I am making an Android application that will remain offline most of the time. The application will need to sync with a MS SQL server database when it connects to wifi. The on-board database is SQLite. I am also very new to Java/Android development so I apologize if I'm missing the obvious somewhere.
I am able to make transactions with MS SQL server quite well using the JTDS driver however when I am querying the MS SQL server, I end up with a ResultSet object that I have to loop through one row at a time. Is there a tool/method out there than can simply insert all rows from a ResultSet into a SQLite database table?
I am currently using the standard:
ArrayList<ArrayList<String>> table = new ArrayList<>(); // a list of lists to represent a table
ArrayList<String> row = new ArrayList<>(); // a list to represent a row of the table
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next())
{
row = new ArrayList<>();
for (int i = 1; i < meta.getColumnCount() + 1; i++) // load data into List
{
row.add(rs.getString(i));
}
table.add(row);
}
From here I was going to loop through my list and add each row one by one to the SQLite database table. This seems inefficient to me. Was just looking for a better way to copy table from MS SQL Server to SQLite on an Android device.
java
|
show 5 more comments
up vote
2
down vote
favorite
A little background: I am making an Android application that will remain offline most of the time. The application will need to sync with a MS SQL server database when it connects to wifi. The on-board database is SQLite. I am also very new to Java/Android development so I apologize if I'm missing the obvious somewhere.
I am able to make transactions with MS SQL server quite well using the JTDS driver however when I am querying the MS SQL server, I end up with a ResultSet object that I have to loop through one row at a time. Is there a tool/method out there than can simply insert all rows from a ResultSet into a SQLite database table?
I am currently using the standard:
ArrayList<ArrayList<String>> table = new ArrayList<>(); // a list of lists to represent a table
ArrayList<String> row = new ArrayList<>(); // a list to represent a row of the table
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next())
{
row = new ArrayList<>();
for (int i = 1; i < meta.getColumnCount() + 1; i++) // load data into List
{
row.add(rs.getString(i));
}
table.add(row);
}
From here I was going to loop through my list and add each row one by one to the SQLite database table. This seems inefficient to me. Was just looking for a better way to copy table from MS SQL Server to SQLite on an Android device.
java
Looks like aSELECT INTOcould do the trick, quick and easy. w3schools.com/sql/sql_select_into.asp
– Kling Klang
Nov 9 at 17:10
1
@KlingKlang Because 'newtable' and 'oldtable' are from 2 totally different types of databases on two separate devices. I can't run a SQLite query from the Android app and query a MS SQL database with that query. I have to first get the data from the MS SQL Server, which will leave me with a JBDC/JTDS ResultSet object, as described in my post.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 17:27
1
@KlingKlang I could convert the ResultSet to a CSV somehow I'm sure but wouldn't that just be extra overhead? Like I said, I can parse the ResultSet into a SQLite table but it seems inefficient. I think it would be just as inefficient to go from ResultSet to CSV to SQLite table.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:13
1
@KlingKlang Though I do see a Linked Server option using an ODBC driver where I might be able to query MS SQL Server from SQLite: link and link. Maybe I'll give that a whirl.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:22
1
Or the other way around. (Throwing an INSERT INTO command from SQL Server to SQLite)
– Kling Klang
Nov 9 at 18:47
|
show 5 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
A little background: I am making an Android application that will remain offline most of the time. The application will need to sync with a MS SQL server database when it connects to wifi. The on-board database is SQLite. I am also very new to Java/Android development so I apologize if I'm missing the obvious somewhere.
I am able to make transactions with MS SQL server quite well using the JTDS driver however when I am querying the MS SQL server, I end up with a ResultSet object that I have to loop through one row at a time. Is there a tool/method out there than can simply insert all rows from a ResultSet into a SQLite database table?
I am currently using the standard:
ArrayList<ArrayList<String>> table = new ArrayList<>(); // a list of lists to represent a table
ArrayList<String> row = new ArrayList<>(); // a list to represent a row of the table
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next())
{
row = new ArrayList<>();
for (int i = 1; i < meta.getColumnCount() + 1; i++) // load data into List
{
row.add(rs.getString(i));
}
table.add(row);
}
From here I was going to loop through my list and add each row one by one to the SQLite database table. This seems inefficient to me. Was just looking for a better way to copy table from MS SQL Server to SQLite on an Android device.
java
A little background: I am making an Android application that will remain offline most of the time. The application will need to sync with a MS SQL server database when it connects to wifi. The on-board database is SQLite. I am also very new to Java/Android development so I apologize if I'm missing the obvious somewhere.
I am able to make transactions with MS SQL server quite well using the JTDS driver however when I am querying the MS SQL server, I end up with a ResultSet object that I have to loop through one row at a time. Is there a tool/method out there than can simply insert all rows from a ResultSet into a SQLite database table?
I am currently using the standard:
ArrayList<ArrayList<String>> table = new ArrayList<>(); // a list of lists to represent a table
ArrayList<String> row = new ArrayList<>(); // a list to represent a row of the table
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next())
{
row = new ArrayList<>();
for (int i = 1; i < meta.getColumnCount() + 1; i++) // load data into List
{
row.add(rs.getString(i));
}
table.add(row);
}
From here I was going to loop through my list and add each row one by one to the SQLite database table. This seems inefficient to me. Was just looking for a better way to copy table from MS SQL Server to SQLite on an Android device.
java
java
edited Nov 9 at 17:09
Kling Klang
32.1k156287
32.1k156287
asked Nov 9 at 16:56
Smitty-Werben-Jager-Manjenson
789
789
Looks like aSELECT INTOcould do the trick, quick and easy. w3schools.com/sql/sql_select_into.asp
– Kling Klang
Nov 9 at 17:10
1
@KlingKlang Because 'newtable' and 'oldtable' are from 2 totally different types of databases on two separate devices. I can't run a SQLite query from the Android app and query a MS SQL database with that query. I have to first get the data from the MS SQL Server, which will leave me with a JBDC/JTDS ResultSet object, as described in my post.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 17:27
1
@KlingKlang I could convert the ResultSet to a CSV somehow I'm sure but wouldn't that just be extra overhead? Like I said, I can parse the ResultSet into a SQLite table but it seems inefficient. I think it would be just as inefficient to go from ResultSet to CSV to SQLite table.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:13
1
@KlingKlang Though I do see a Linked Server option using an ODBC driver where I might be able to query MS SQL Server from SQLite: link and link. Maybe I'll give that a whirl.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:22
1
Or the other way around. (Throwing an INSERT INTO command from SQL Server to SQLite)
– Kling Klang
Nov 9 at 18:47
|
show 5 more comments
Looks like aSELECT INTOcould do the trick, quick and easy. w3schools.com/sql/sql_select_into.asp
– Kling Klang
Nov 9 at 17:10
1
@KlingKlang Because 'newtable' and 'oldtable' are from 2 totally different types of databases on two separate devices. I can't run a SQLite query from the Android app and query a MS SQL database with that query. I have to first get the data from the MS SQL Server, which will leave me with a JBDC/JTDS ResultSet object, as described in my post.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 17:27
1
@KlingKlang I could convert the ResultSet to a CSV somehow I'm sure but wouldn't that just be extra overhead? Like I said, I can parse the ResultSet into a SQLite table but it seems inefficient. I think it would be just as inefficient to go from ResultSet to CSV to SQLite table.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:13
1
@KlingKlang Though I do see a Linked Server option using an ODBC driver where I might be able to query MS SQL Server from SQLite: link and link. Maybe I'll give that a whirl.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:22
1
Or the other way around. (Throwing an INSERT INTO command from SQL Server to SQLite)
– Kling Klang
Nov 9 at 18:47
Looks like a
SELECT INTO could do the trick, quick and easy. w3schools.com/sql/sql_select_into.asp– Kling Klang
Nov 9 at 17:10
Looks like a
SELECT INTO could do the trick, quick and easy. w3schools.com/sql/sql_select_into.asp– Kling Klang
Nov 9 at 17:10
1
1
@KlingKlang Because 'newtable' and 'oldtable' are from 2 totally different types of databases on two separate devices. I can't run a SQLite query from the Android app and query a MS SQL database with that query. I have to first get the data from the MS SQL Server, which will leave me with a JBDC/JTDS ResultSet object, as described in my post.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 17:27
@KlingKlang Because 'newtable' and 'oldtable' are from 2 totally different types of databases on two separate devices. I can't run a SQLite query from the Android app and query a MS SQL database with that query. I have to first get the data from the MS SQL Server, which will leave me with a JBDC/JTDS ResultSet object, as described in my post.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 17:27
1
1
@KlingKlang I could convert the ResultSet to a CSV somehow I'm sure but wouldn't that just be extra overhead? Like I said, I can parse the ResultSet into a SQLite table but it seems inefficient. I think it would be just as inefficient to go from ResultSet to CSV to SQLite table.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:13
@KlingKlang I could convert the ResultSet to a CSV somehow I'm sure but wouldn't that just be extra overhead? Like I said, I can parse the ResultSet into a SQLite table but it seems inefficient. I think it would be just as inefficient to go from ResultSet to CSV to SQLite table.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:13
1
1
@KlingKlang Though I do see a Linked Server option using an ODBC driver where I might be able to query MS SQL Server from SQLite: link and link. Maybe I'll give that a whirl.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:22
@KlingKlang Though I do see a Linked Server option using an ODBC driver where I might be able to query MS SQL Server from SQLite: link and link. Maybe I'll give that a whirl.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:22
1
1
Or the other way around. (Throwing an INSERT INTO command from SQL Server to SQLite)
– Kling Klang
Nov 9 at 18:47
Or the other way around. (Throwing an INSERT INTO command from SQL Server to SQLite)
– Kling Klang
Nov 9 at 18:47
|
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230161%2fcopy-ms-sql-server-table-to-sqlite-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Looks like a
SELECT INTOcould do the trick, quick and easy. w3schools.com/sql/sql_select_into.asp– Kling Klang
Nov 9 at 17:10
1
@KlingKlang Because 'newtable' and 'oldtable' are from 2 totally different types of databases on two separate devices. I can't run a SQLite query from the Android app and query a MS SQL database with that query. I have to first get the data from the MS SQL Server, which will leave me with a JBDC/JTDS ResultSet object, as described in my post.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 17:27
1
@KlingKlang I could convert the ResultSet to a CSV somehow I'm sure but wouldn't that just be extra overhead? Like I said, I can parse the ResultSet into a SQLite table but it seems inefficient. I think it would be just as inefficient to go from ResultSet to CSV to SQLite table.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:13
1
@KlingKlang Though I do see a Linked Server option using an ODBC driver where I might be able to query MS SQL Server from SQLite: link and link. Maybe I'll give that a whirl.
– Smitty-Werben-Jager-Manjenson
Nov 9 at 18:22
1
Or the other way around. (Throwing an INSERT INTO command from SQL Server to SQLite)
– Kling Klang
Nov 9 at 18:47