- java database connection jdbc odbc how to connect java to database database connectivity simple code for java database connectivity
Code Snippet :
import java.sql.*;
class insertIntoTable
{
public static void main(String args[]) {
try {
//load database driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//connect To database
Connection c;
c=DriverManager.getConnection("jdbc:odbc:RS");
System.out.println("connect To database");
//create Statement
Statement s;
s=c.createStatement();
//create String
String x;
x="INSERT into RS Values ('Shiva','Aiwale','Vita',21)";
//execute query
s.executeUpdate(x);
System.out.println("Data Successfully Inserted");
c.close();
}
catch(Exception e) {
System.out.println("Exception ="+e.getMessage());
}
}
}
class insertIntoTable
{
public static void main(String args[]) {
try {
//load database driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//connect To database
Connection c;
c=DriverManager.getConnection("jdbc:odbc:RS");
System.out.println("connect To database");
//create Statement
Statement s;
s=c.createStatement();
//create String
String x;
x="INSERT into RS Values ('Shiva','Aiwale','Vita',21)";
//execute query
s.executeUpdate(x);
System.out.println("Data Successfully Inserted");
c.close();
}
catch(Exception e) {
System.out.println("Exception ="+e.getMessage());
}
}
}
No comments:
Post a Comment