-1
내가 제목과 메일 메시지 BU를 우편으로 메일을 추천 pakets을 읽고있다하지만 난 여기에이 오류가 발생했습니다 데이터베이스에 데이터를 삽입하고 때
코드의 somne 부분입니다닫히지 않은 인용 표시가
aSocket.receive(to);
String towards=new String(to.getData());
System.out.println(towards);
aSocket.receive(sub);
String subject=new String(sub.getData());
aSocket.receive(msg);
String message=new String(msg.getData());
sendedmail(towards,subject,message,username);
public void sendedmail(String to,String sub,String msg,String from){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
}
try{
Connection con=DriverManager.getConnection("jdbc:odbc:udp");
Statement st=con.createStatement();
int status=0;
String query;
query = "INSERT INTO emails(emailto, emailfrom, message, userstatus, subject) VALUES('"+to+"','"+from+"','"+msg+"','"+status+"','"+sub+"')";
int f=st.executeUpdate(query);
if(f==1){
System.out.println("row inserted");
}
else
{
System.out.println("row not inserted");
}
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
}
createStatement 대신 preparedStatement를 사용하지 않습니까? 따라서 작은 따옴표 문제는 피할 수 있습니다. – user75ponic
http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html - http://en.wikipedia.org/wiki/SQL_injection –
그리고 JDBC/ODBC 브리지를 사용하지 않아야합니다. 항상 버그가 있고 느리고 Java8에서 더 이상 지원되지 않습니다. 대신 실제 JDBC 드라이버를 사용하십시오. –