Test JDBC drivers

Maggot 0 Tallied Votes 240 Views Share

a simple program to test the JDBC drivers.

import java.sql.*;

public class TestJdbc {
	static String sql = "select * from test_table where column1 = ?"; 

	static String userId = "userid";
	static String password = "password";
	static String dbServer = "dbserver";
	static String dbName = "database";
	
	public static void main(String[] args) throws Exception {
		testMSDriver();
	}

	private static void testMSDriver() throws Exception {
		Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
		Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+ dbServer +";SendStringParametersAsUnicode=false;dataSourceName=SQL2000JDBC;databaseName="+ dbName +";serverName="+ dbServer +";selectMethod=cursor", userId, password);

		long start = System.currentTimeMillis();
		PreparedStatement stmt = conn.prepareStatement(sql);
		stmt.setString(1, "string1");
		ResultSet rs = stmt.executeQuery();

		while (rs.next()) {
	 		// System.out.println("Result: " + rs.getString(1));
		}
		conn.close();
		System.out.println("Elapsed time for MS driver: " + 
						(System.currentTimeMillis() - start));
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.