• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Facing problem mysql connection in struts application

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You didn't tell me he was so big. Unlike this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic