Sample Program using JDBC




package com.javastuff.jdbc;


import java.sql.*;
/**
 * @author JavaStuff
 */
public class JDBCExample
{
public static void main(String args[])throws SQLException,ClassNotFoundException
{
String driverClassName="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:JavaStuff";
String username="scott";
String password="tiger";


String query = "insert into students values (100, \'JavaStuff\')";


//Load driver class
Class.forName(driverClassName);


// Obtain a connection
Connection con=DriverManager.getConnection(url,username,password);


// Obtain a Statement
Statement st=con.createStatement();

//Execute the Query
int count=st.executeUpdate(query);


System.out.println("Number of Rows Effected by this query = "+count);
}//main
}//class







Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email