|
-
Apr 18th, 2007, 09:35 AM
#1
Thread Starter
Lively Member
JSP Page
I have one problem that i dont know anything about Java or JSP or any web technology and my boss has given me this code to use in JSP page and test whether its working or not. I know this will be quite easy for you guys so pls help me out how to use this code and test it ..
Code:
public Connection getCon() throws java.sql.SQLException{
Connection connection = null;
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dburl = "jdbc:microsoft:sqlserver://elogix:1433;DatabaseName=DSI";
String uid="sa";
String pwd="ipnc0176";
try{
Class.forName(driver).newInstance();
}catch(Exception cnfe){
System.out.println("Unable to load Driver class");
throw new SQLException("Unable to Load Driver:"+cnfe.getMessage());
}
try{
System.out.println("Getting connection...");
connection=DriverManager.getConnection(dburl,uid,pwd);
}catch(java.sql.SQLExcetion sqle){
System.out.println("SQL Exception (Connection):");
throw new SQLException("SQL Exception (Connection):"+sqle.getMessage());
}
return connection;
}
-
Apr 18th, 2007, 03:37 PM
#2
Re: JSP Page
Code:
String uid="sa";
String pwd="ipnc0176";
I do hope you changed these before posting.
Except for the typo here:
Code:
}catch(java.sql.SQLExcetion sqle){
I see no reason why the code shouldn't work. It's very poorly written code, yes, with some bad and some strange practices, but it's correct. You will need this at the top of the JSP page:
Code:
<% @page import="java.sql.Connection"
import="java.sql.DriverManager"
import="java.sql.SQLException" %>
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 20th, 2007, 02:04 AM
#3
Thread Starter
Lively Member
Re: JSP Page
I am now getting error "Unable to load driver class" wat could be the reason ?
"Pls excuse i m asking basic question as i dont have any knowledge of java"
-
Apr 20th, 2007, 03:31 AM
#4
Re: JSP Page
It means, most likely, that the database driver is not installed correctly to be found by the webapp.
There should be a JAR containing the driver somewhere. Best method is to put it into the servlet container's "common" directory, where libraries shared by the container and the webapps reside, but you could also put it into the webapp's WEB-INF/lib directory.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|