java connectivity

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 40
Reputation: coolbuddy059 has a little shameless behaviour in the past 
Solved Threads: 0
coolbuddy059 coolbuddy059 is offline Offline
Light Poster

java connectivity

 
0
  #1
Mar 31st, 2009
I have to make a database in oracle and connect it with Java. But I'm not able to do so.
Please help.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: java connectivity

 
0
  #2
Mar 31st, 2009
Originally Posted by coolbuddy059 View Post
I have to make a database in oracle and connect it with Java. But I'm not able to do so.
Please help.

I want to make a space ship and fly back to my home on Mars, please help me too.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,217
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: java connectivity

 
0
  #3
Mar 31st, 2009
@coolbuddy059 please provide your current code so we may have look at it and correct it if there is any issue

PS:In the future please provide more info, if you wish to avoid general suggestions such as one by stephen. Secondly we have rule that says "We only give homework help to those who show effort"
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 40
Reputation: coolbuddy059 has a little shameless behaviour in the past 
Solved Threads: 0
coolbuddy059 coolbuddy059 is offline Offline
Light Poster

Re: java connectivity

 
0
  #4
Mar 31st, 2009
sorry stephen84s for unclearity in my question,
But the problem is I've crated the database using Oracle8i.But now I don't know what to do next.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 40
Reputation: coolbuddy059 has a little shameless behaviour in the past 
Solved Threads: 0
coolbuddy059 coolbuddy059 is offline Offline
Light Poster

Re: java connectivity

 
0
  #5
Mar 31st, 2009
My code is:-

import java.sql.*;

import java.io.*;



public class dbcon{

public static void main(String[] args) {

Connection connection = null;

try {

// Load the JDBC driver

String driverName = "oracle.jdbc.driver.OracleDriver";

Class.forName(driverName);



// Create a connection to the database

//String serverName = "127.0.0.1";

//String portNumber = "1521";

//String sid = "oracle";

String url = "jdbc:oracle:thin//local.server:1521/oracle";

String username = "scott";

String password = "tiger";

connection = DriverManager.getConnection(url, username, password);

System.out.println("***Connected to the database***");

} catch (ClassNotFoundException e) {

// Could not find the database driver

} catch (SQLException e) {

// Could not connect to the database



}

}


The compilation error whichI'm getting is:
The pointer has reached at the end of line while parsing} ->
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,217
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: java connectivity

 
0
  #6
Mar 31st, 2009
As error message states you missing closing bracket "}" on the end of your code. If you check your code you will find that main() was closed, however you did not do same for the class
Last edited by peter_budo; Mar 31st, 2009 at 8:10 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: java connectivity

 
1
  #7
Apr 1st, 2009
Peter has already mentioned the cause of your problem, now just wanted to add a few notable things like :-
  1. You never closed your connection, Its important to close your database connection once you are done using it. Preferably put the call to close() inside a finally block, so that your database connection is closed irrespective of whether an SQLException was thrown during your query execution etc.
  2. In the catch block where you have caught your SQLException always print / log the SQL State by calling e.getSQLState(), by comparing the SQL State with your DBMS vendor data example here, you can map out exactly why your query failed.
Last edited by stephen84s; Apr 1st, 2009 at 1:35 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC