Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8291055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:00:01+00:00 2026-06-08T13:00:01+00:00

I have jsp form : <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html>

  • 0

I have jsp form :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="./Styles/Site.css" type="text/css" />
<title>Create new customer</title>
</head>
<body>
    <fieldset>
        <legend>Create new customer</legend>
        <form action="CreateCustomerServlet" method="GET">
            // text of form ... 
            <input type="submit" value="Create customer" />
        </form>
    </fieldset>

</body>
</html>

that go to CreateCustomerServlet –

package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import Model.Customer;
import Model.Gender;

/**
 * Servlet implementation class CreateCustomerServlet
 */
@WebServlet("/CreateCustomerServlet")
public class CreateCustomerServlet extends HttpServlet {
    // members ..

    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public CreateCustomerServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        // get the parameters from the jsp form  .. 
            saveInDB() ; 
    }

    private void saveInDB() throws ClassNotFoundException, SQLException {

        Connection connection = null;
        try {
            String strServer = "jdbc:mysql://127.0.0.1:3306/testdb";
            MysqlDataSource ds = new MysqlConnectionPoolDataSource();
            ds.setServerName(strServer);
            ds.setDatabaseName("testdb");
            connection = ds.getConnection("root", "");
            Statement statement = connection.createStatement();
            statement.execute(" /** sql INSERT statement **/");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}

when it get to the line – connection = ds.getConnection("root", ""); it throws exception – com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "mysql:"'.

I use with MySql , in http://localhost/phpmyadmin/ I have a DB testdb with the users as in the snapshot –

enter image description here

and both of the user have empty password as the snapshot –

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:00:05+00:00Added an answer on June 8, 2026 at 1:00 pm

    You mix 2 different ways to establish a connection.

    You can do :

    MysqlDataSource ds = new MysqlDataSource();
    ds.setServerName("localhost");
    ds.setPort("3306");
    ds.setDatabaseName("testdb");
    ds.setUser("root");
    ds.setPassword("");
    Connection connection = ds.getConnection();
    

    or

    Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb","root","");
    

    By the way it’s a good practice to put the connection settings in a property file. You should read this excellent post and this related article.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jsp page - <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html>
I have this jsp page - <%@page import=java.text.Normalizer.Form%> <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01
I have this form in jsp page - <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01
I have a jsp with a submit based on the html:form action. <html:form action=/nextPath>
I have a jsp page(let's say page1.jsp) which have an html form with action=page2.jsp.
I have an html/jsp form that I am serializing(using jquery) and passing to a
I have a JSP html based form. I want to do the post through
I have a jsp/html form that collects an array of choices from user. For
I have a jsp form validate.jsp which contains 2 text fields where user enters
I have created one jsp form which contains the username textfield. On the click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.