Results 1 to 5 of 5
- 04-14-2012, 12:39 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
trouble with connecting database in a servlet
I tried to connect DB in a servlet. So I made ConnecDB function like below, and this funciton will be called in doPost method of the servlet. However, this function does not connect to DB. Do you know why?
I don't understand because when I run exact same function in another class's main, it works.
public static void ConnectDB(){
Connection c =null;
try{
String connectionString = "jdbc:hsqldb:hsql://localhost:9001";
c = DriverManager.getConnection(connectionString); //connect!!
}// end of try
catch(SQLException e){
System.out.println("\n--- SQLException caught ---\n");
while (e != null)
{
System.out.println("Message: " + e.getMessage());
System.out.println("SQLState: " + e.getSQLState());
System.out.println("Vendor ErrorCode: " + e.getErrorCode());
e = e.getNextException();
System.out.println();
}
}// end of catch
catch(Exception e){
e.printStackTrace();
}// end of catch
finally{
if (c !=null){
try{
c.close();
}
catch(Exception e2){
//do nothing - can't do anything anyway.
}
}// end of if
}// end of finally
}
- 04-16-2012, 10:54 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,449
- Rep Power
- 16
Re: trouble with connecting database in a servlet
What errors/exceptions do you get?
Please do not ask for code as refusal often offends.
- 04-17-2012, 09:07 AM #3
JavaDoctor
- Join Date
- Apr 2012
- Location
- Internet
- Posts
- 7
- Rep Power
- 0
Re: trouble with connecting database in a servlet
Yes, please paste the exceptions that is displayed. If you were able to access the database using the same function in the scripts located in the same server/system, then you may have to analyze the DB privileges too.
- 04-17-2012, 09:38 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,449
- Rep Power
- 16
Re: trouble with connecting database in a servlet
Until we see the exception there's little point preempting the cause of the problem.
Please do not ask for code as refusal often offends.
- 05-31-2012, 09:54 AM #5
Member
- Join Date
- Mar 2012
- Posts
- 41
- Rep Power
- 0
Re: trouble with connecting database in a servlet
Try my book of dirty tricks here...
http://www.nicephotog-jsp.net/QueryU...and_source.zip
Similar Threads
-
Trouble connecting to my database,
By KyleS in forum JDBCReplies: 1Last Post: 02-22-2012, 09:34 AM -
connecting to a database
By mxb7642 in forum JDBCReplies: 5Last Post: 09-08-2009, 08:39 AM -
connecting to a database
By kswiss in forum NetBeansReplies: 4Last Post: 06-25-2009, 06:22 PM -
Connecting JSP with database
By ramachandran in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 05-13-2009, 06:15 AM -
Connecting to a database
By peiceonly in forum New To JavaReplies: 2Last Post: 04-06-2008, 02:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks