【发布时间】:2020-05-17 16:29:10
【问题描述】:
我尝试检查标识符是否存在,但出现线路错误
st = Connecter.getConnection().prepareStatement(query)
出现错误:找不到符号 符号:方法prepareStatement(String) 位置:类对象
并在行中
catch (SQLException ex) {
Logger.getLogger(Login_Form.class.getName()).log(Level.SEVERE, null, ex);
出现错误找不到符号 符号:类 SQLException 位置:类Login_Form
这是我的全部代码
PreparedStatement st;
ResultSet rs;
// donnez l'username et le password
String username = jTextField_Username.getText();
String password = String.valueOf(jPasswordField.getPassword());
// requete indiquant si les identifiants existent
String query = "SELECT * FROM 'users' WHERE 'username' = ? AND 'password' = ?";
try {
st = Connecter.getConnection().prepareStatement(query)
st.setString(1, username);
st.setString(2, password);
rs = st.executeQuery();
if(rs.next())
{
// Show my new form
}else{
// Error message
}
} catch (SQLException ex) {
Logger.getLogger(Login_Form.class.getName()).log(Level.SEVERE, null, ex);
}
我的连接器页面:
package javaapplicationhotel2;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.sql.*;
/**
*
* @author camil
*/
public class Connecter {
static Object getConnection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
Connection con;
public Connecter() {
try{
Class.forName("com.mysql.cj.jdbc.Driver");
}catch(ClassNotFoundException e){
System.err.println(e);
}
try{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/hotel","root","");
}catch(SQLException e){System.err.println(e);}
}
Connection obtenirconnexion(){return con;}
PreparedStatement prepareStatement(String select__from_classe) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
你有解决办法吗?
【问题讨论】: