User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 427,940 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,656 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Aug 12th, 2006
Views: 4,250
a simple program to test the JDBC drivers.
Last edited : Aug 14th, 2006.
java Syntax | 5 stars
  1. import java.sql.*;
  2.  
  3. public class TestJdbc {
  4. static String sql = "select * from test_table where column1 = ?";
  5.  
  6. static String userId = "userid";
  7. static String password = "password";
  8. static String dbServer = "dbserver";
  9. static String dbName = "database";
  10.  
  11. public static void main(String[] args) throws Exception {
  12. testMSDriver();
  13. }
  14.  
  15. private static void testMSDriver() throws Exception {
  16. Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
  17. Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+ dbServer +";SendStringParametersAsUnicode=false;dataSourceName=SQL2000JDBC;databaseName="+ dbName +";serverName="+ dbServer +";selectMethod=cursor", userId, password);
  18.  
  19. long start = System.currentTimeMillis();
  20. PreparedStatement stmt = conn.prepareStatement(sql);
  21. stmt.setString(1, "string1");
  22. ResultSet rs = stmt.executeQuery();
  23.  
  24. while (rs.next()) {
  25. // System.out.println("Result: " + rs.getString(1));
  26. }
  27. conn.close();
  28. System.out.println("Elapsed time for MS driver: " +
  29. (System.currentTimeMillis() - start));
  30. }
  31. }
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 6:45 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC