Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- how to execute bulk insert statement in java (using JDBC) with db=SQL Server 2008 Express
- BULK INSERT SalesHistory FROM 'c:SalesHistoryText.txt' WITH (FIELDTERMINATOR = ',')
- public void insertdata(String filename)
- {
- String path = System.getProperty("user.dir");
- String createString = "BULK INSERT Assignors FROM " + path + "\" +filename+ ".txt WITH (FIELDTERMINATOR = ',')";
- try
- {
- // Load the SQLServerDriver class, build the
- // connection string, and get a connection
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- String connectionUrl = "jdbc:sqlserver://arvind-pc\sqlexpress;" +
- "database=test01;" +
- "user=sa;" +
- "password=password1983";
- Connection con = DriverManager.getConnection(connectionUrl);
- System.out.println("Connected.");
- // Create and execute an SQL statement that returns some data.
- String SQL = "BULK INSERT dbo.Assignor FROM " + path + "\" +filename+ ".txt WITH (FIELDTERMINATOR = ',')";
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(SQL);
- // Iterate through the data in the result set and display it.
- while (rs.next())
- {
- //System.out.println(rs.getString(1) + " " + rs.getString(2));
- System.out.println(" Going through data");
- }
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- System.exit(0);
- }
- }
- String SQL = "BULK INSERT dbo.Assignor FROM '" + path + "\" +filename+ ".txt' WITH (FIELDTERMINATOR = ',')";
Add Comment
Please, Sign In to add comment