• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

connection object question

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to create an instance variable of the Connection object to utilize in a JUnit test I am trying to compile. However I am getting the following error:

Cannot instantiate the type Connection, since it is not a concrete class

I am just trying to do:

Connection con = new Connection();

Is there a way to get around this to get this instance variable created?

Any help or direction would be appreciated. I've tried googling for an answer but I could not find anything that I could understand as to what they were trying to accomplish.

Thanks!!
[ August 04, 2005: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is not the way to create a connection. You need to find yourself a JDBC tutorial.

Perhaps this one.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

Thanks for the reply. I am already making a connection as below:

public Connection getConnection(){
// Make connection to a SQL Server 2000 database.
Connection con = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+ HOST_NAME +":1433;DatabaseName="+ DB_NAME +";User="+ USER_NAME +";Password="+ PASSWORD +"");
}
catch (Exception e) {
fail("Get Connection getConnection threw an exception: " +(e.getMessage()));
}
return con;
}

What I want to do is setup an INSTANCE VARIABLE for con instead of a local variable. I am wondering if I can do that from the connection object?

Sorry that I was not clear.

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What I want to do is setup an INSTANCE VARIABLE for con instead of a local variable.



I have no idea why you think that makes any difference. How you obtain a connection has no bearing on what kind of variable you store it in.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Melinda,

part actually does the magic. The static block in SQLServerDriver Class calls DriverManager Class' static method register and registers itself.

Say 5 such classes registered themselves separately to the DriverManager; then depending on the getConnection() method's URL Parameter : that specific Driver Class is called by the DriverManager.


Actually a Driver class might trick the DriverManager and can handle the connections to other RDBMS's also. But it must have written the logic to talk to that specific DB of course.
[ August 04, 2005: Message edited by: Yilmaz Mete ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic