Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie help please on SQL connection problem

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When stepping thru my SQL Connection method:

public Connection SQLConn(){
Connection con = null;
String hostname = "localhost"; // local machine
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+ hostname +":1433;DatabaseName=esdev;User=test;Password=test");
}
catch (Exception e) {
System.out.println(e.getMessage());
}
finally {
if(con != null){
try { con.close(); }
catch (Exception e) {System.out.println("Error closing connection: " + e.getMessage());
}
}
}
return con;
}

I am getting this exception when I hit the bolded line above:

ClassNotFoundException
cause = null
detailMessage="com.microsoft.jdbc.sqlserver.SQLServerDriver"
ex=null
stackTrace=null
walkback = int[37]

I inserted the 3 mssqlserver jar files in the BUILD PATH. I've also run another method that attaches to the sql server just fine.

Any direction or help would be appreciated.

Regards.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the SQL server drivers jars are in the classpath you use when you run this code then it should be OK. How are you running it?
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

Thanks for the reply. I am working in the IBM RAD 6.0 IDE environment. After consulting with one of our IBM RAD contractors here he found that I had to put the .jar files in the WEB_INF\lib folder. Which I did and now I am somewhat connecting to the SQL Server.

NOW, my problem is that my program is blowing up on the source content of the msbase.jar file is not found.

Here is my connection code and the bolded line below is where is it blowing up (are the parameters case sensitive since this is SQL?):

// Method to get a connection to a SQL Server 2000 database.
public Connection SQLConn(){
Connection con = null;
String hostname = "localhost"; // local machine
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+ hostname +":1433;DatabaseName=esdev;User=test;Password=test");
}
catch (Exception e) {
System.out.println(e.getMessage());
}
finally {
if(con != null){
try { con.close(); }
catch (Exception e) {System.out.println("Error closing connection: " + e.getMessage());
}
}
}
return con;
}

Again, any direction or help is appreciated. Regards.
[ July 27, 2005: Message edited by: Melinda Savoy ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes. If you are running this as a web app, you will need all dependent jars in WEB-INF/lib.

What is the exception message you are seeing? (I presume when you say the source content of msbase.jar is not found you mean it is not found by the debugger while you step through htis code?)
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. I am new to this tool and using the debugger I found that I should have stepped over not stepped into where I thought I had a problem and consequently I found that I did not have an error after all. The problems I encountered were due to me not having the VALUE string in single quotes.

I sure hate that I wasted your time, but appreciate it very much.

Regards.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't sweat it. Mistakes are easy to make.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic