aspose file tools*
The moose likes JDBC and the fly likes Newbie help please on SQL connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Newbie help please on SQL connection problem" Watch "Newbie help please on SQL connection problem" New topic
Author

Newbie help please on SQL connection problem

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Apr 14, 2004
Posts: 10336

Don't sweat it. Mistakes are easy to make.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie help please on SQL connection problem
 
Similar Threads
Question on Unhandled Exception - please help!
SQL Server Connection question
HELP - newbie question on JDBC
Passing values into the SQL connection class?
SQL Server DB connection