package test;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import com.mysql.jdbc.PreparedStatement;public class ConnectionTest { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub } private Connection getConnection() throws SQLException {
Connection conn = null;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url, user, pwd);
} catch (ClassNotFoundException e) { }
return conn;
} public void Query() throws SQLException {
Connection conn = this.getConnection();
String strsql = "select * from booklist.userlogin where name=?";
Statement stmt = conn.createStatement();
PreparedStatement pstmt = conn.prepareStatement(strsql);
//这一句出现错误提示:Type mismatch: cannot convert from PreparedStatement to PreparedStatement pstmt.setString(1, "jack");
ResultSet rs = pstmt.executeQuery(); } String driverName = "com.mysql.jdbc.Driver";
String user = "root";
String pwd = "mysql";
String url = "jdbc:mysql://localhost:3306";
}