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 {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (java.lang.ClassNotFoundException e) {
			System.out.println(e.getMessage());
		}
		try {
			conn = DriverManager.getConnection(url);
		} catch (SQLException ex) {
			System.out.println(ex.getMessage());
		}
	}
then anothe class code is 
public void addUser(String userName, String userPasswd, int userPower) {
		userCheck=1;
		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!

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.

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).

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.