0% found this document useful (0 votes)
6 views4 pages

JDBC Programs

Uploaded by

ManuHiremattBS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

JDBC Programs

Uploaded by

ManuHiremattBS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.sql.

*;

public class OdbcAccessConnection {

public static void main(String [] args) {

Connection con = null;

try {

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

// Connect with a url string

con = DriverManager.getConnection("jdbc:odbc:data");

System.out.println("Connection ok.");

con.close();

} catch (Exception e) {

System.err.println("Exception: "+e.getMessage());

}
import java.sql.*;

public class OdbcAccessCreateTable {

public static void main(String [] args) {

Connection con = null;

try {

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

con = DriverManager.getConnection("jdbc:odbc:data");

// Creating a database table

Statement sta = con.createStatement();

int count = sta.executeUpdate(

"CREATE TABLE HY_Address (ID INT, StreetName VARCHAR(20),"

+ " City VARCHAR(20))");

System.out.println("Table created.");

sta.close();

con.close();

} catch (Exception e) {

System.err.println("Exception: "+e.getMessage());

} } }
import java.sql.*;

public class OdbcAccessInsertRows {

public static void main(String [] args) {

Connection con = null;

try {

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

con = DriverManager.getConnection("jdbc:odbc:data");

Statement sta = con.createStatement();

// insert 3 rows

int count = 0;

int c = sta.executeUpdate("INSERT INTO HY_Address"

+ " (ID, StreetName, City)"

+ " VALUES (1, '5 Baker Road', 'Bellevue')");

count = count + c;

c = sta.executeUpdate("INSERT INTO HY_Address"

+ " (ID, StreetName, City)"

+ " VALUES (2, '25 Bay St.', 'Hull')");

count = count + c;

c = sta.executeUpdate("INSERT INTO HY_Address"

+ " (ID, StreetName, City)"

+ " VALUES (3, '251 Main St.', 'W. York')");

count = count + c;

System.out.println("Number of rows inserted: "+count);

sta.close();

con.close();
} catch (Exception e) {

System.err.println("Exception: "+e.getMessage());

You might also like