aspose file tools*
The moose likes Struts and the fly likes Facing problem mysql connection in struts application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Facing problem mysql connection in struts application" Watch "Facing problem mysql connection in struts application" New topic
Author

Facing problem mysql connection in struts application

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi All,

I am new to Struts and trying to create a small application. I am using NetBeans 6.1 IDE and mysql database shipped with the IDE.
But the application is not able to connect to the database.
Below is the that particular code.




I am using GlassFish app server. When i run the application i am getting below lines in the app server console.




I have included mysql-connector-java-3.0.10-stable-bin.jar, mysql-connector-java-3.0.16-ga-bin.jar, commons-dbcp.jar, mysql-connector-java-5.1.10-bin.jar while trying different approach to connect to the database but all in vain.

I tried with other sample java program (only .java file) and tried to connect with the same driver and mysql database which is working perfectly.
Even i tried with another mysql driver org.gjt.mm.mysql.Driver but in vain. I tried with DBCP also by declaring everything in struts-config.xml but also not worked.

I am not getting any exception/ error while running above code but not even getting statements from the declaration of driver and onwards.

Please help me in above. I have been trying on this from last 5 days.
Please let me know if anything is required.

Thanks in advance.


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

This doesn't seem to have anything to do with Struts. Only one version of the mysql connector library is enough for this to work, so you can just include mysql-connector-java-5.1.10-bin.jar in your project. When Netbeans deploy the project, make sure that the mysql-connector-java-5.1.10-bin.jar is actually transferred to the WEB-INF/lib directory of the deployed project...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Thanks Ankit.


When Netbeans deploy the project, make sure that the mysql-connector-java-5.1.10-bin.jar is actually transferred to the WEB-INF/lib directory of the deployed project...


Do i need to check above in the app server's console?

Thanks.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Generally netbeans does in-place deployment. So you can go to the <project folder>\deploy\WEB-INF\lib directory to check if the mySql connector actually gets packaged in your project. Which version of MySql are you using?? Also can you check the server logs to see if there's actually any stack trace related to the error you have shown us (apart from what you see in the server console in netbeans, the logs may contain something more)...
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Ankit,

Thanks for reply.

I checked but there is no such folder called deploy under my project folder. But i tried to find the mysql-connector-java-5.1.10-bin.jar in the app server's trace but i am not able to find it there. So i think its not transffered while the project is being deployed. So what is the next step do i need to do to make it worked?

Thanks in Advance.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Sorry, the name of the directory is build, so the path is <project folder>\build\WEB-INF\lib.

To ensure that the library is packaged with your project, right click on your project from your project window, click on properties, from the categories box choose Libraries. On the right you'll see the libraries in your project, make sure that the "package" checkbox is checked for the mysql connector library (jar)...
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Ankit,

Thanks for your valuable response.

mysql-connector-java-5.1.10-bin.jar is present in the build/WEB-INF/lib folder and "package" checkbox is checked for the mysql connector library (jar) when i right click on the project name and checked in the library in my project category. What could the reason for this issue/problem?

Thanks in Advance.
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Ankit,

It seems that its working fine now. because i am able to get the record which is there in the table.
I made only change in the below line.

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/logon","root","");

Remove the spaces between the commas.

Thanks.


Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
But i think spaces should not be the problem because i purposely keep the spaces again and still its working.

Not sure as nothing got the changes but i copied the driver and other things from working .java file and just replaces the name according to our requirements.

Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Facing problem mysql connection in struts application