473,513 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database connection problem

12 New Member
i placed every thing in proper place(i.e in lib folder ) and placed in class path also...

but still i am facing problem is that when i run my application i am unable to get any response......that is in browser i didnt notice anything.....


my code is:

i have database called ravi and one table named kumar.

<%
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433,ravi";
Connection con=DriverManager.getConnection
("url","sa","sa");
out.println("connected");
Statement st=con.createStatement();
ResultSet re=sql.executeQuery("select * from stuinfo");
String sql ="INSERT INTO kumar VALUES('Michael','dba','9000')";
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}


i m not getting the stmt written in out.println();

i think the problem is occuring at connection statement.....

the jar files i mentioned in lib folder are sqljdbc.jar,odbd14.jar,jtdc-1.2.jarmsutil.jar,msbase.jar,mssqlserver.jar,class es111.jar

i put these in class path also....

tell me where am i doing wrong?

is any intermediate cinnector is required like in the case of my sql?

thanks in advance

ragards
ravi......
Feb 7 '07 #1
5 1541
acoder
16,027 Recognized Expert Moderator MVP
This is not a Coldfusion problem. I'll redirect you to the Java forum.
Feb 7 '07 #2
r035198x
13,262 MVP
i placed every thing in proper place(i.e in lib folder ) and placed in class path also...



but still i am facing problem is that when i run my application i am unable to get any response......that is in browser i didnt notice anything.....





my code is:



i have database called ravi and one table named kumar.



<%

try

{

Class.forName(\"com.microsoft.sqlserver.jdbc.SQLSe rverDriver\");

String url=\"jdbc:microsoft:sqlserver://localhost:1433,ravi\";

Connection con=DriverManager.getConnection

(\"url\",\"sa\",\"sa\");

out.println(\"connected\");

Statement st=con.createStatement();

ResultSet re=sql.executeQuery(\"select * from stuinfo\");

String sql =\"INSERT INTO kumar VALUES(\'Michael\',\'dba\',\'9000\')\";

con.close();

}

catch (Exception e)

{

e.printStackTrace();

}

}





i m not getting the stmt written in out.println();



i think the problem is occuring at connection statement.....



the jar files i mentioned in lib folder are sqljdbc.jar,odbd14.jar,jtdc-1.2.jarmsutil.jar,msbase.jar,mssqlserver.jar,class es111.jar



i put these in class path also....



tell me where am i doing wrong?



is any intermediate cinnector is required like in the case of my sql?



thanks in advance



ragards

ravi......


Now doni, multi posting is not a very good thing to do in these forums. I appreciate that you have had this problem for a long time now and also feel bad that we have not been able to help you out yet but just keep posting for this problem in the same thread in this forum.



You said there is nothing shown on the browser, are there any exceptions being thrown?
Feb 7 '07 #3
abctech
157 New Member
i placed every thing in proper place(i.e in lib folder ) and placed in class path also...

but still i am facing problem is that when i run my application i am unable to get any response......that is in browser i didnt notice anything.....


my code is:

i have database called ravi and one table named kumar.

<%
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433,ravi";
Connection con=DriverManager.getConnection
("url","sa","sa");
out.println("connected");
Statement st=con.createStatement();
ResultSet re=sql.executeQuery("select * from stuinfo");
String sql ="INSERT INTO kumar VALUES('Michael','dba','9000')";
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}


i m not getting the stmt written in out.println();

i think the problem is occuring at connection statement.....

the jar files i mentioned in lib folder are sqljdbc.jar,odbd14.jar,jtdc-1.2.jarmsutil.jar,msbase.jar,mssqlserver.jar,class es111.jar

i put these in class path also....

tell me where am i doing wrong?

is any intermediate cinnector is required like in the case of my sql?

thanks in advance

ragards
ravi......
Hi doniravi,

I am not sure if this can help you but try declaring the Connection object in the declarative tag instead of the scriptlet and register your driver and get the connection in jspInt() and close it in jspDestroy()

I am working with MySql and Type1 driver so I would normally do as foll:-

Expand|Select|Wrap|Line Numbers
  1. <%!
  2.     Connection con;
  3.  
  4.     public void jspInit()
  5.     {
  6.      try
  7.      {
  8.       DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
  9.       con = DriverManager.getConnection("jdbc:odbc:<your dsn name>");                 
  10.      }        
  11.      catch(Exception e)
  12.      {
  13.      System.out.println(e);                
  14.      }    
  15.     }
  16.  
  17.     public void jspDestroy() 
  18.     {
  19.      try
  20.      {
  21.       con.close();
  22.      }
  23.      catch(Exception e)
  24.     {
  25.       System.out.println(e);    
  26.     }
  27.    }
  28.  
  29.  %>
  30.  <%
  31.    //then creating the Statement,ResultSet, executing the query etc I do in the scriptlet
  32.  
  33.  %>
See if doing the above helps you in any way..and if it doesn't then do post your exceptions, maybe someone can help you after having a look at them!

By the way a simple thing I would like to share--
If you arent a pro and you really wanna know which part of your program is giving error put SOP's at regular intervals so that way based on the SOP's that've printed on the server's console you can get a rough idea about where your code is stuck!!

This is what works for me(Most Times, Not All !!).Maybe doesn't get the problem solved but atleast I know uptill where my code is actually working ..and which part is giving the problem..then accordingly you can work on the erroneous code!Later you can just remove the SOP's once your code is fully up and running!

Cheers
Feb 7 '07 #4
Banfa
9,065 Recognized Expert Moderator Expert
Someone with more knowledge of java than me will have to confirm this but is this really right

Expand|Select|Wrap|Line Numbers
  1. String url="jdbc:microsoft:sqlserver://localhost:1433,ravi";
  2. Connection con=DriverManager.getConnection("url","sa","sa"); 
  3.  
shouldn't it be

Expand|Select|Wrap|Line Numbers
  1. String url="jdbc:microsoft:sqlserver://localhost:1433,ravi";
  2. Connection con=DriverManager.getConnection(url,"sa","sa"); 
  3.  
otherwise you are using the string "url" rather than the string contained in the variable url.



P.S. I would just like to re-itterate what r035198x has already said about NOT double posting.
Feb 7 '07 #5
r035198x
13,262 MVP
Someone with more knowledge of java than me will have to confirm this but is this really right



Expand|Select|Wrap|Line Numbers
  1.  
  2. String url=\"jdbc:microsoft:sqlserver://localhost:1433,ravi\";
  3.  
  4. Connection con=DriverManager.getConnection(\"url\",\"sa\",\"sa\"); 
  5.  
  6.  


shouldn\'t it be



Expand|Select|Wrap|Line Numbers
  1.  
  2. String url=\"jdbc:microsoft:sqlserver://localhost:1433,ravi\";
  3.  
  4. Connection con=DriverManager.getConnection(url,\"sa\",\"sa\"); 
  5.  
  6.  


otherwise you are using the string \"url\" rather than the string contained in the variable url.







P.S. I would just like to re-itterate what r035198x has already said about NOT double posting.


You should pay us more frequent visits Banfa. That is probably the reason why the code is not working. The exception stack trace would confirm this but doni did not give it.
Feb 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

14
4780
by: Nick Gilbert | last post by:
Hi, I have an asp.net application which runs from a CD-ROM using Cassini. As such, it is single user only. The application connects to an Access database when it is loaded, and keeps the same connection open all the time (as it's single user, this shouldn't be a problem). There is logic in the code to ensure that the connection is
7
2217
by: News | last post by:
Hello, I have to build a program with the future in mind and I need a bit of guidance from a guru or two. My program will start as a multi-user Windows Application built with VB.Net and using an Access 2002 database backend. The future will require that 1. The database be switched with minimal effort to SQL Server and 2. A Web Application...
2
15230
by: Ron St-Pierre | last post by:
We're developing a java app and are using postgres as the database. On our dev server I started the app, closed it, but the java process was still open so I killed it, which caused the above error. I've had to do this in the past but have not had this happen before. I've searched the archives and found a message/reply from Andrew Sullivan...
10
9571
by: mjf | last post by:
Hello, We made a backup image file for a database on one machine (A), and we restored the database on another machine (B), using the backup image file. Everything went fine. But when we try to connect to the database on B, it's taking forever (about 1 minute) if it's the first connection to the database. Any following connections have no...
3
10274
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not...
5
1625
by: Sam | last post by:
Hi all, I have a process which first pulls one time all application IDs from a database and stores them in a table(this process works fine everytime). I then loop through the table, one at a time, and use application id to pull details info and process it. For example, if I have 500 records in my table, then I would have to open database...
18
9106
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft page "How to: Connect to Data in an Access Database"
5
3368
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open left, I always see that there are 2 connections open and in "ESTABLISHED" state. Here is the piece of code that I'm using, please tell where I'm...
8
2820
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is put into stand-by or hibernation 3. later, computer is brought out of stand-by or hibernation 4. when trying to save or close form, SQL exception...
39
5825
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.