Image via Wikipedia
Hey friends I am here to help you. In this tutorial we will see how to insert data into oracle data base using java program/application.Prerequisites:
- All configuration must me done to connect java
Image via Wikipedia
application to oracle before starting this task. As described in my previous tutorial 'How to connect java application with oracle database'.
- First start your oracle database and create a table of your choice. eg - create table student (id number(3), name varchar2(30),class number(2),marks number(3));
- Now open IDE and write down the java code for the application which will connect to the oracle database and enter the data to the specific table.
- After compilation and execution. You will get data inserted in the database.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class InsertRecord {
public static void main(String[] args) {
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String cs="jdbc:odbc:connect_oracle";
String user = "system";
String pwd = "tom";
String sqlstmt="INSERT INTO STUDENT VALUES(1,'Steve',5,70)";
Connection con = null;
Statement st = null;
try
{
Class.forName(driver);
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("Driver loaded");
try
{
con=DriverManager.getConnection(cs,user,pwd);
System.out.println("Connected to the Oracle Database");
st = con.createStatement();//creates a
Statement
object for sending SQL statements to the database.int updatecount=st.executeUpdate(sqlstmt);//return either the row count for
INSERT
, UPDATE
or DELETE
statements, or 0
for SQL statements that return nothingSystem.out.println(updatecount+" row inserted");
}
catch(Exception e)
{
System.out.println(e);
}
try
{
st.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}//main()
}//class()
Output:
Driver loaded
Connected to the Oracle Database
1 record inserted
In my next post I will discuss about how to add interactively multiple records to the oracle database. Till then have a good time.
27 comments:
thanks man it was very helpful for me.....atleast I cud understand where I was making a mistake....hats off to U......cheers..
Swapnil Walke
hi plz . tell how to insert values at run time?
thanku very much...god bless you
hiii
please help me out i am not able to connect to Data Base: i get an Exception like:
ORA-12514:TNS:listner could not resolve SERVICE_NAME given in connect desriptor
DataSourceName: Oracle
Platform:Windows XP
my code:
public static void main(String[] args) {
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String cs="jdbc:odbc:Oracle";
String user = "scott";
String pwd = "tiger";
String sqlstmt="INSERT INTO STUDENT VALUES(2,'Steve',50)";
Connection con = null;
Statement st = null;
try
{
Class.forName(driver);
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("Driver loaded");
try
{
con=DriverManager.getConnection(cs,user,pwd);
System.out.println("Connected to the Oracle Database");
st = con.createStatement();//creates a Statement object for sending SQL statements to the database.
int updatecount=st.executeUpdate(sqlstmt);//return either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
System.out.println(updatecount+" row inserted");
}
catch(Exception e)
{
System.out.println(e);
}
try
{
st.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}//main()
}//class()
please let me know!! please reply
thank u for giving explanation very gud explanation
excellent post
sir,
am govardhan while an trying to connect am getting this error plz help me
am using oracle 10 g
usr name is scott and password is tiger
plz forword ans to my mail id plz plz
my mail id is (govardhandevari@gmail.com)
C:\Documents and Settings\DIGIT\Desktop>java Test1 Exception in thread "main" java.lang.UnsupportedClassVersionError: Test1 (Unsupported major.minor version 50.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
plz help me how to connect java and oracle 10g
C:\Program Files\Java\jdk1.6.0_21\bin>javac Inser.java
C:\Program Files\Java\jdk1.6.0_21\bin>java Inser
Driver loaded
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS
:could not resolve the connect identifier specified
java.lang.NullPointerException
C:\Program Files\Java\jdk1.6.0_21\bin>javac Inser.java
C:\Program Files\Java\jdk1.6.0_21\bin>java Inser
Driver loaded
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS
:could not resolve the connect identifier specified
java.lang.NullPointerException
i got the above error while running ur code so please guide me to connect to oracle database from java. Actually i am using oracle10g, jdk1.6.0_21
thank u so much..............
done a great job.............it s usefulll for begineers.......as like me........
this is very easy way of jdbc with oracle
thanks sir
not any error in this program
JDBC Driver loaded
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-06413: Connection not open.
Connected to the Oracle Database
java.lang.NullPointerException
JDBC Driver loaded
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-06413: Connection not open.
Connected to the Oracle Database
java.lang.NullPointerException
this is the error i am getting plz help me
hey i am getting an error
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
i have copied ojdbc14.jar in my lib folder but still it is giving the same exception
i tried it on eclipse also and include external jar but getting the same error ...pls tell me how to resolve this...
Ankara
Antalya
istanbul
Ordu
izmir
Z1FMR1
izmir
Erzurum
Diyarbakır
Tekirdağ
Ankara
5HRVEV
yozgat
sivas
bayburt
van
uşak
70E
02361
Gümüşhane Evden Eve Nakliyat
Niğde Evden Eve Nakliyat
Muğla Evden Eve Nakliyat
Kırıkkale Parça Eşya Taşıma
Ankara Evden Eve Nakliyat
0BCA7
Bayburt Şehir İçi Nakliyat
Bitlis Şehirler Arası Nakliyat
Ankara Boya Ustası
Ünye Marangoz
Denizli Parça Eşya Taşıma
Çerkezköy Petek Temizleme
Mardin Lojistik
İstanbul Lojistik
Edirne Şehir İçi Nakliyat
2617E
Maraş Lojistik
Etlik Boya Ustası
Shibanomi Coin Hangi Borsada
Hakkari Şehir İçi Nakliyat
Erzincan Parça Eşya Taşıma
Gölbaşı Fayans Ustası
Tekirdağ Şehir İçi Nakliyat
Ankara Evden Eve Nakliyat
Uşak Lojistik
39480
Tunceli Parça Eşya Taşıma
Sivas Evden Eve Nakliyat
Karaman Evden Eve Nakliyat
Tokat Lojistik
Nevşehir Lojistik
Kastamonu Parça Eşya Taşıma
İzmir Şehirler Arası Nakliyat
Amasya Şehirler Arası Nakliyat
Çerkezköy Çilingir
B2B85
adana canli sohbet chat
malatya yabancı görüntülü sohbet
mersin kadınlarla sohbet
Kilis Kızlarla Rastgele Sohbet
osmaniye canli sohbet chat
Balıkesir Bedava Sohbet Uygulamaları
yabancı görüntülü sohbet siteleri
ısparta Telefonda Görüntülü Sohbet
karabük canli sohbet bedava
5732B
kırşehir yabancı görüntülü sohbet siteleri
canli sohbet
Uşak Muhabbet Sohbet
kastamonu rastgele görüntülü sohbet uygulaması
Tokat Rastgele Sohbet Siteleri
çanakkale sohbet siteleri
canlı sohbet ücretsiz
Osmaniye Telefonda Kadınlarla Sohbet
Tekirdağ En İyi Rastgele Görüntülü Sohbet
BEB00
ledger live
poocoin
looksrare
arculus
metamask
phantom
poocoin
safepal
defillama
67385
uwulend finance
DefiLlama
dexview
thorchain
spookyswap
satoshivm
defillama
pancakeswap
dappradar
2B5DCD2057
steroid satın al
görüntülü show
cialis
steroid satın al
www.ijuntaxmedikal.store
şov
Post a Comment
Type here your comments