Writing a program to determine management level ID's from a database. I've used this same connection method through the site over and over but it doesn't hang anywhere else. However, those methods aren't buried within an actual class. Is there any reason why putting this particular code into a java class would make it hang?
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import oracle.jdbc.driver.OracleDriver;
import java.sql.*;
public class connection
{
public Connection getDBConnection()
{
java.sql.Connection conn=null;
try
{
DriverManager.registerDriver(new OracleDriver());
conn = DriverManager.getConnection("stuff"); //Hangs here for like 2 seconds
}
catch (Exception e)
{
e.printStackTrace();
}
return conn;
}
}
Just to reiterate, I use this via a straight up jsp (no classes in that jsp) throught the site, but for this particular segment, I implemented it as a method within a class. This seems to be the only place where it hangs. Also, if you could give me the specific imports to make the database connection work so I can get rid of some of those ".*"...that would be awesome. Thanks
Edit: For more clarity, I create object X and in object X it creates the connection class object which calls this method.
So,
someClass whatever = new someClass();
Connection conn = null;
conn = whatever.getDBConnection(); //hangs
Connection); You only need to importjava.sql.DriverManager, andoracle.jdbc.driver.OracleDriver; Change your return type tojava.sql.Connectionif you adjust your class name; Database connections from the JSP should be avoided in most cases... you should have a data access layer that does this.