473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

java to oracle database connection

Hello everyone, i'm new here and i'm having some problem with connecting my tables in oracle and editing (update/delete) them in a java app i'm building. a short example would also help. i am using oracle 10g.
thanks.
Oct 20 '07 #1
2 1846
rahana
12
import java.sql.*;

public class Stmt
{
public static void main(String args[])throws Exception
{

try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin: @localhost:1521:xe","scott","tiger");
Statement stmt=con.createStatement();
String vsql="create table testtable(cone number,ctwo number)";
stmt.executeUpdate(vsql);
System.out.println("...Success....");
con.close();
}
catch(ClassNotFoundException e)
{
System.out.println(e);
System.out.println("hello");
}

}
}
--------------------------------------------------------------------------------------------------------------------
ur url might change depending up on ur username,password.data source name etc.

u can use various statement like
String vsql=insert into Student values("+vstudno+",' "+vstudname+" ');

executeUpdate must be used for executing non select statements.
executeQuery must be used for executing select statements.
example:
Statement stmt=con.CreateStatement();
String vsql="select * from Student";
ResultSet rs=stmt.executeQuery(vsql);
while(rs.next())
{
System.out.println("current row--->"+rs.getRow())
}
con.close();
}
}
Oct 20 '07 #2
JosAH
11,448 Expert 8TB
@Rahana: so you managed to make a database connection? What did you change?
I can't find any difference between your non-working version and this one.

kind regards,

Jos
Oct 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Harry | last post by:
Using Oracle 8i enterprise on win 2000 (sp3) Installed the standard configuration & whenever I make a connection it takes about 10 secs. It's running on a P1900 with 1gb Ram so no reason there...
1
by: CM | last post by:
Hi, when i want connect me in my BD with a JSP (with this simple code), this exception is throw. Thank's for ur help Mathieu CODE of my JSP ---------------------
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
0
by: ʹÃûÑï | last post by:
ORA-03114: not connected to ORACLE && MS's Bug?? DataBase:Oracle 817 using OracleClient,net framework 1.1 I'm using ADO.Net in C# with Oracle 817. and following is my public data access...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
3
by: owen | last post by:
Hi, I've been trying for ages to connect to my Oracle 9.2.0 database from Java. I am attempting to create a thin connection. The necessary drivers were installed with the database and I have...
3
by: rahana | last post by:
My java programme is unable to connect to the database.. my code is this import java.sql.*; public class Stmt { public...
2
by: meenuchotijuhi | last post by:
Hi, I've Recently joined this community coz i m very much interested in Oracle DBA track. Actaully I' m currently working on a project where I m using Java (jdk1.4) as front end and Oracle 9i as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.