• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change sid in program

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I want to change the sid in the URL i.e(conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger");. My requirement is that the user must be asked for the SID and the SID should be set. I can do that if i have one or two URL's. The problem is that i have used it many times the URL in different classes. Now what can i do to achieve my requirement.



Thanks and Regards
alexander
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're trying to change the underlying connection properties of an existing connection, you may need to establish a new one on the fly by building a new connection string.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

adeeb alexander wrote:....The problem is that i have used it many times the URL in different classes. Now what can i do to achieve my requirement...

Fix that first.
Then, if your requirement is that the user has to select the database when your program starts, it should not be difficult to implement.
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.
Sorry for late reply.

i have tried creating a different class for connection to database. I get few errors and couldn't solve. Little help required. The code is below

Conection.java



exp.java




i am getting error at line "Statement stmt = con.createStatement();" the error is " cannot find symbol method con.createStatement". Please point at my mistake.


Thanks and Regards
alexander
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your "Conection" class does not include a method called createStatement.
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how could i do it can you say me please.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get rid of Conection and use Connection directly?
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you mean that i should use the Connection class directly. The problem is in my real application i needed to establish connection many times so to get rid of that i created a new connection class. The advantage is that if the database changes also, it will be easy to change the SID and all the crap. So i thought it will be flexible o use a different connection class.
Hope you got me.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You created your own connection class? More likely you wrapped a connection class, as creating a 'true' JDBC connection class would be... difficult.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

adeeb alexander wrote:The advantage is that if the database changes also, it will be easy to change the SID and all the crap.


I have to echo Scott's comment, writting the code to handle all the database nuts and bolts yourself in a custom connection class sounds way harder than just using the one the driver provides.

Why is the SID so important?
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am concerned about SID becuase i have to run the application on other system where the database already installed. The SID of that db would be different. What shall i do in that case.



Thanks.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about providing an extrernal configuration file that includes the database details?
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The !dea is good. How can i implement it. Need a small example. Thanks for your patience and support Paul.


Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you could just use a properties file and the Properties class. Or you could go further an use a DataSource.
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
Please see the code below and suggest me. Please tell me what i have done is good or not.

DBConnection.java



exp.java




I get the output. Please tell me is there any drawback in doing like that or will be there any problem in future if i try to do something different.


Thanks and Regards
alexander
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not good. You create two connections. One in line 11 and 1 in line 21.
You use the one from line 11.
You get a new one in line 21, and close it immediately.
You don't close the one from line 11.
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cumps.
Thanks for your reply. There is a advantage if i use the above method, because where ever there is a change in connection parameters i have to change at one place only. Can you tell me how can i overcome the above drawback.

Thanks.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need a DBConnection object, but a Connection object...

With this Connection object, you can do what ever you will do on the DB - and when you are finish with it you close it in a finally block (together with the Statement and ResultSet objects).
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you said is wright Rene. Now suppose 10 classes are there each class has code related to transaction with the database, then i have to use the Connection object 10 times. I should also give all the parameters i.e SID username and password. I don't want to do that. Instead do something where i have to give all those at only one place. Hope you got me.


Thanks.
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using the Connection(s) from a standalone Application or from a Web Server??

If it is from a standalone Application, then you need to code a Connection Pool class collection, where YOU control how connections are started and closed - and how they are re-newed or closed after a number of time used (or what you decide).
When your application start up ALL connections will be generated as you have decided they should be (how many initial, how many allowed idle - etc.)

If you are using a Web Server, you need to set up the connection to use on the server - then they will be handled by the web container.

Maybe you can use some of these Open Source DB Pools: http://java-source.net/open-source/connection-pools
 
reply
    Bookmark Topic Watch Topic
  • New Topic