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 9030307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:27:29+00:00 2026-06-16T07:27:29+00:00

Hello everyone i am developing simple jsp file which takes some info from students

  • 0

Hello everyone i am developing simple jsp file which takes some info from students like name,gender,skills etc and i am directing it to servlet and given database connections her.But when i run the code its not connecting to db. Can some one please help me out. Here is my servlet code

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException 
{
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    Connection con=null;
    String url ="jdbc:mysql://localhost:3306/";
    String dbName="student_db";
    String driver = "com.mysql.jdbc.Driver";
    String username = "root";
    String password = "admin";


    String bttn_value = request.getParameter("submit");
    if(bttn_value.equalsIgnoreCase("submit"))
    {
        String name = request.getParameter("fname");

        String gender = request.getParameter("gender");
        String skill ="";
        System.out.println("2222222222");
        String skills[]= request.getParameterValues("skill");
        for(int i=0;i<skills.length;i++)
        {
            skill +=skills[i]+",";
        }
        String addr=request.getParameter("adname");
        String country = request.getParameter("country");
        Statement stmt;

    try
    {
        System.out.println("444444444444");
        Class.forName(driver).newInstance();
        System.out.println("333333333");
        con = DriverManager.getConnection(url + dbName, username,
                password);

        System.out.print("Connected to database");
        String query1= "insert into student values  name='"
             +name +"',gender='"+gender+ "',skills='"+skill + "',addname='" 
             +addr +"',country='" +country +"'";
        stmt =con.createStatement();
        stmt.executeUpdate(query1);
        out.print("<br>");
        response.sendRedirect("std.jsp");
        con.close();
        System.out.print("Disconnected from DB");

    }
    catch (Exception e)
    {
        out.println(e.getMessage());
        System.out.println("123456");

    }

and here is my console
enter image description here

and the output what i am getting

enter image description here

Thank you in advance, any help is appreciable.

  • 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-16T07:27:31+00:00Added an answer on June 16, 2026 at 7:27 am

    The code does not need to create a new instance to register the driver. Class.forName(driver); will suffice.

    try
    {
        System.out.println("444444444444");
        Class.forName(driver);
        System.out.println("333333333");
        con = DriverManager.getConnection(url + dbName, username,
                password);
    
        System.out.print("Connected to database");
        String query1= "insert into student values  name='"
             +name +"',gender='"+gender+ "',skills='"+skill + "',addname='" 
             +addr +"',country='" +country +"'";
        stmt =con.createStatement();
        stmt.executeUpdate(query1);
        out.print("<br>");
        response.sendRedirect("std.jsp");
        con.close();
        System.out.print("Disconnected from DB");
    
    }
    

    Also make sure the MySql JDBC driver is in your classpath. You can download the jar or pull it in from maven.

    Maven

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.21</version>
    </dependency>
    

    Direct Download

    To import the jar, first download the jar file and place it within your file system, preferably within your project.

    1. In Eclipse right click your project and select properties, then
      Java Build Path.
    2. Next click the Libraries tab and click Add JARs (if .jar is in
      your project) or Add External Jars (if .jar is outside).
    3. Find the jar file and click OK.

    enter image description here

    To get more useful debugging information, try printing the stacktrace in your catch, this can be removed once the problem is resolved. I suspect it will tell you that it cannot find the mysql driver.

    catch (Exception e)
    {
        e.printStackTrace();
        out.println(e.getMessage());
        System.out.println("123456");
    
    }
    

    If your issue is still not resolved, post this stacktrace with your question.

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

Sidebar

Related Questions

Hello everyone i am working on a project which requires me to export some
Hello Everyone, I am developing an app which have to show all the restaurants
Hello good morning everyone, I am developing an iphone app which provide push notification
Hello everyone I would like to ask how to check value's length from textbox
Hello everyone I would like to ask how to redirect from one view to
hello everyone im trying to create this tweak that copies a file from one
Hello everyone, I am making a VC++ 2008 project in pure Win32 API which
Hello everyone, I have some confusion regarding some Win32 API data types and macros
Hello everyone i am developing an quiz based app in android and i have
Hello everyone it's been some days that I use sql to make analysis and

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.