package com.t4b.jdbc.oracle.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class TestMain {
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
String name = "PHP";
String author = "John";
String publisher = "Oxf";
Connection con = null;
Statement stmt = null;
try {
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "pass123");
stmt = con.createStatement();
stmt.executeUpdate("insert into books values ('" + name + "', '" + author + "', '" + publisher + "')");
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
Oracle JDBC Insert Data Using Statement Interface
Share This
Tags
# Java Database Connection
# Technology
Share This
About BunksAllowed
Technology
Labels:
Java Database Connection,
Technology
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.