このコードは、mysqlテーブルに挿入レコードがありますが、ログインのように既に存在しているmysqlカラムとjsp/html textboxes文字列を比較したいと思います。これは私がmysqlデータベーステーブルレコードから2つの入力文字列を比較するには?
- が
- が、私はこれを行うことができますどのようにMySQLの列データを入力文字列を比較mysqlのクエリを変更するには知っていページが
2つのことをログインするのですか?
NewServlet.java
public class NewServlet1 extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name=request.getParameter("username");
String abc=request.getParameter("password");
aaaa c1=new aaaa();
try{
String Sql="Select * from login where username='"+name+"' AND password='"+abc+"'";
c1.st.executeUpdate(Sql);
}
catch(SQLException ex)
{
out.println(ex);
}
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet1</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet NewServlet1 at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
aaaa.java //このクラスは//
public class aaaa {
Connection c1 = null;
Statement st = null;
ResultSet rs = null;
aaaa(){
try {
Class.forName("com.mysql.jdbc.Driver");
c1 = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/teacher","root", "abcde");
}
catch (Exception cnfe) {
System.out.println("Couldn't find the driver!");
System.out.println("Couldn't connect: print out a stack trace and exit.");
System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
}
try {
st = (Statement) c1.createStatement();
System.out.println("Statement Created Successfully");
} catch (SQLException se) {
System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
se.printStackTrace();
}
if (c1 != null) {
System. out.println("Hooray! We connected to the database!");
} else {
System.out.println("We should never get here.");
}
}
}
あなたは[SQLインジェクション攻撃](http://bobby-tables.com) –
に脆弱ですなぜ私のコードを改善しようとしませんか?私はあなたのコードがテーブルにデータを挿入していますが、ユーザー名やパスワードのような入力文字列からテーブルの既存のデータを比較したい場合 –
まず宿題をしなければならないからです。 SQLを学ぶには、利用可能なチュートリアルがたくさんあります(例えば、[Code School](https://www.codeschool.com/courses/try-sql)の無料コース) - 特に、 'SELECT'コマンドとその' WHERE'節。あなたは基本を教えてくれるわけではありません。 –