This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Struts - MYSQL connection not working  RSS feed

Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Some how managed to bring up my form. Now I have problem in sending data from the GUI. Below is the connection code. Can some one place check and tell what may be the problem.

package com.admin;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Admin {
   public static Connection conn() throws Exception {
       return DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "");

   public static int Register(RegisterAction jjform) {
       int flag = 0;
       try {
           PreparedStatement ps = conn().prepareStatement("INSERT INTO jjform VALUES(?,?,?,?)");
           ps.setInt(1, jjform.getIdjjform());
           ps.setString(2, jjform.getFname());
           ps.setString(3, jjform.getLname());
           ps.setString(4, jjform.getCname());
           flag = ps.executeUpdate();
       } catch (Exception e) {
       return flag;


I dont get any http or any error. When I input the data in the GUI I get my error.jsp page displayed.
Ranch Hand
Posts: 127
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, allthough it's hard to read w/o code tags and bad translation, there seems nothing wrong with your code. Also: please explain what you expect to happen and what actualy happen instead.

A few notes:
Class.forName is no longer needed since jdbc4 - as long as the driver is in classpath it gets loaded by serviceloader when calling drivermanager

also - you connect as root w/o password - wich is only possible in a fresh clean uninitialized install of mysql/mariadb - but if this would be your problem you would get an exception on the line you connect - so this seems also not a problem

add debug lines to check if the posted code gets called as you think it is - most likely you passing in an invalid object - in the off-chance the code is run at all
Vani Jay
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suddenly when all is well, I am getting an error with this Struts-tags even though I have imported the Struts lib to Eclipse under Web-INF/lib. When I Run in Eclipse, it gives error like below:

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Unable to find taglib [s] for URI: [/struts-tags]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.


org.apache.jasper.JasperException: Unable to find taglib [s] for URI: [/struts-tags]
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/8.5.30


My Code:

<%@taglib uri="/struts-tags" prefix="s"%>
<head><title>Participant Contact Form</title></head>
<body style="background-color: lightyellow;">
<div style="margin-left: 25%; margin-top: 50px;">
<h1>Participant Info</h1>
<s:form action="Register.action"/>
<s:lable name="Participant ID" value="idjjform" />
  <s:lable name="Participant ID" value="idjjform" />
<s:textfield label="fname" name="fname" />
<s:textfield label="Lname" name="lname" />
<s:textfield label="Cname" name="cname" />

<s:submit value="Register" />
Posts: 506
Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not familiar with Struts, but the error encountered may be a configuration issue (this might be within the JSP or WEB.XML). I found these while I searched the net:

- Tag-lib issue with migrating Struts2 to Tomcat 8.Its working on tomcat7:
- Struts 2 Annotation Tutorial 1:

Also, the link to how to UseCodeTags on JavaRanch posts.
Prasad Saya
Posts: 506
Java Notepad
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When working with web apps, a database connection can be acquired using a Data Source (rather than a DriverManager). According to Oracle's Java documentation its a preferred way of to get connection objects.

Connecting with DataSource Objects (Oracle's Java Tutorials):
Have you no shame? Have you no decency? Have you no tiny ad?
Programmatically Create PDF Using Free Spire.PDF with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!