Posts

Showing posts from December, 2009

JDBC Connectivity to Various Databases and SQL Query Syntax

Image
This writeup gives us an idea of the jar files and the drivers required to connect to various databases. We have chosen six databases for this purpose and they are MySQL,Oracle,MS SQL Server-2000,MS SQL Server-2005,Sybase and Apache Derby. We need to have suitable jar files to establish connections to corresponding databases. No need to set these jar files in Environment Variables or in any classpath. We will load the jar files dynamically.Here is the java code to establish connection to various DBs. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class JDBCConnectivityAndSQLQuerySyntax { private static String driver = null; private static String url = null; private static String userId = null; p...