I m a freshman about JSP.Now I have a quesstion about sql.
first I made a class.Code is

public class DataBase {
	protected String url = "jdbc:mysql://localhost:3306/lab?user=root&password=root&"
			+ "useUnicode=true&characterEncoding=utf-8";

	public Connection conn = null;
	public DataBase() {
		try {
		} catch (java.lang.ClassNotFoundException e) {
		try {
			conn = DriverManager.getConnection(url);
		} catch (SQLException ex) {
then anothe class code is 
public void addUser(String userName, String userPasswd, int userPower) {
		sql="insert into user(userPasswd,userPower,userName,userCheck)values(?,?,?,?)";
		pstm=dataBase.conn.prepareStatement(""); <-here is a err it is 
Type mismatch: cannot convert from PreparedStatement to PreparedStatement.
I do not know why?

thank first!

8 Years
Discussion Span
Last Post by cjkennedyo

You have problem with yours prepareStatement.
Have look at this tutorial it will explain it to you. After that if you still have problems just post bellow.

Hi peter_budo,

I have the exact same problem as jacky_cheng; I have followed the tutorial to no avail. I am using Eclipse, and it is highlighting my prepared statement declaration stating "Type mismatch: cannot convert from PreparedStatement to PreparedStatement". This makes no sense to me. What is trying to be converted?

Here is the relevant code:

Connection conn = DriverManager.getConnection(dbConnectString, dbUser, dbPass);
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM table WHERE id = ?");

Thanks for any help you may provide.


I figured it out I believe. Apparently, Eclipse added

import com.mysql.jdbc.PreparedStatement;

for me, even though I already had

import java.sql.*;

I am not sure why this happened, but wanted to update this post for anyone else out there using Eclipse that has a similar problem.

If someone feels like explaining this to me, please do. I am still very much a novice and would love to learn more about this (pointing me to docs is ok too).


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.