Thursday, September 18, 2008

Database connectivity using MySQL with JDBC Driver.


The Code Goes Like This :


Class.forName("org.gjt.mm.mysql.Driver").newInstance(); // " "---> JDBC driver
location


Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306
/contacts/", props);
// " " --> database file location and name

Statement stmt = con.createStatement();

String query = ... // define query

stmt.executeQuery(query);


Database connectivity using IBM DB2 with JDBC Driver.


The Code Goes Like this :



Driver driver = new COM.ibm.db2.jdbc.app.DB2Driver();

DriverManager.registerDriver(driver);

connection = DriverManager.getConnection("jdbc:db2:", "username", "password");

if (connection == null)

{

System.out.println("connection failed");

}

connection.setAutoCommit(true);

System.out.println("Successfully Connected to DB2...");

statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);



Database connectivity using MS-ACCESS having C# as the Programming language.


The Code Goes Like This :


String constring ="Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C:Database1.mdb";

//Making connecting to MS-ACCESS WITH A CONNECTION STRING OF YOUR DATA BASE

OleDbConnection mycon = new OleDbConnection(constring);

//OPEN METHOD ESTABLISH THE CONNECTION.

mycon.Open();

//Query to retrieve the result for the connection that has opened

String query = "select * FROM Table1";

OleDbCommand cmd = new OleDbCommand ( query,mycon);



Database Connectivity between oracle10g and netbeans 5.5


The code goes like this :


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:msdaora","username",
"password");

Statement stmt = con.createStatement();

Resultset rs=stmt.executeQuery("select * from table name");


Here username and password is the username and password of your database which you are using (eg. oracle,Microspft sql server etc.) and table name refers to the table name that you want to import from database.