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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:31:08+00:00 2026-06-10T06:31:08+00:00

I have connected JAVA application with MySql .When i wrote PreparedStatement ps = null

  • 0

I have connected JAVA application with MySql .When i wrote PreparedStatement ps = null ;
then two option for import package was showing .The two suggested package was :com.mysql.jdbc.PreparedStatement; and java.sql.PreparedStatement .And , when i import com.mysql.jdbc.PreparedStatement package they said for casting as shown below .

ps = (PreparedStatement) con.prepareStatement("INSERT INTO Authors(Name) VALUES(?)");

And when i used java.sql.PreparedStatement not need for casting in above sentence .

so, My question is : why two different import package are showing ? and why casting needed for com.mysql.jdbc.PreparedStatement package ?

  • 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-10T06:31:09+00:00Added an answer on June 10, 2026 at 6:31 am

    why two different import package are showing ?

    Because both classes were present in your compiletime classpath and your IDE were trying to be helpful.


    and why casting needed for com.mysql.jdbc.PreparedStatement package ?

    Because prepareStatement() is specified to return java.sql.PreparedStatement, not com.mysql.jdbc.PreparedStatement.


    The java.sql.PreparedStatement is an interface and you should be using this all the time. The MySQL one is a concrete implementation and you should not be tight coupling your JDBC code to the MySQL specific implementation. Otherwise you’d have to make a lot of changes in your code if you ever want to switch the DB server (and thus also the JDBC driver) to a different vendor like PostgreSQL. If you’re using the standard JDBC interfaces from java.sql package all the time, all you would need to change is only the JDBC URL and maybe also the username and password and some DB-specific SQL statements.

    See also:

    • When should I use an interface in java?
    • In simplest terms, what is a factory?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a java SE application that uses the mysql database using mysql
I have a Java application under Tomcat, connecting to a Postgre and a MySQL
I have a problem with Hibernate (3.6.0.-Final) in my Java EE application using MySQL
We have a java application that connects to mysql database. We are now going
I have a Java application that connects to a MySQL database and uses a
I have 2 displays connected, so I can either launch my Java application on
I have a MySQL database and a java application using it thru JDBC. I
I have never connected to a database in java before. May I know if
I have successfully connected my Oracle 11g XEdatabase with java in Netbeans 7.1. Class.forName(oracle.jdbc.OracleDriver);
I have coded a server in Java that will have several clients connected to

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.