0% found this document useful (0 votes)
4 views2 pages

Java SQL Server Large Data Update

Uploaded by

etest2272
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Java SQL Server Large Data Update

Uploaded by

etest2272
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import [Link].

Reader;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class UpdateLargeData {

public static void main(String[] args) {

// Create a variable for the connection string.


String connectionUrl =
"jdbc:sqlserver://<server>:<port>;databaseName=AdventureWorks;user=<user>;password=
<password>";

// Establish the connection.


try (Connection con = [Link](connectionUrl); Statement
stmt = [Link]();
Statement stmt1 = [Link](ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);) {

createTable(stmt);

// Since the summaries could be large, we should make sure that


// the driver reads them incrementally from a database,
// even though a server cursor is used for the updatable result sets.

// The recommended way to access the Microsoft JDBC Driver for SQL
Server
// specific methods is to use the JDBC 4.0 Wrapper functionality.
// The following code statement demonstrates how to use the
// [Link] and [Link] methods
// to access the driver specific response buffering methods.

if
([Link]([Link])) {
SQLServerStatement SQLstmt =
[Link]([Link]);

[Link]("adaptive");
[Link]("Response buffering mode has been set to " +
[Link]());
}

// Select all of the document summaries.


try (ResultSet rs = [Link]("SELECT Title, DocumentSummary
FROM Document_JDBC_Sample")) {

// Update each document summary.


while ([Link]()) {

// Retrieve the original document summary.


try (Reader reader = [Link]("DocumentSummary"))
{
if (reader == null) {
// Update the document summary.
[Link]("Updating " +
[Link]("Title"));
[Link]("DocumentSummary", "Work in progress");
[Link]();
}
}
}
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
[Link]();
}
}

private static void createTable(Statement stmt) throws SQLException {


[Link]("if exists (select * from [Link] where name =
'Document_JDBC_Sample')"
+ "drop table Document_JDBC_Sample");

String sql = "CREATE TABLE Document_JDBC_Sample (" + "[DocumentID] [int]


NOT NULL identity,"
+ "[Title] [char](50) NOT NULL," + "[DocumentSummary] [varchar]
(max) NULL)";

[Link](sql);

sql = "INSERT Document_JDBC_Sample VALUES ('title1','summary1') ";


[Link](sql);

sql = "INSERT Document_JDBC_Sample (title) VALUES ('title2') ";


[Link](sql);

sql = "INSERT Document_JDBC_Sample (title) VALUES ('title3') ";


[Link](sql);

sql = "INSERT Document_JDBC_Sample VALUES ('title4','summary3') ";


[Link](sql);
}
}

You might also like