請教一下
在下是一名學生 正在寫報告
遇到了一個問題
就是在寫程式時遇到宣告新字串在需要繼承本來寫入的字串時造成無法繼承的狀況導致字串為空值
請各位幫幫忙
以下為程式碼
謝謝!
Server=localhost;Database=master;Trusted_Connection=True;
package cc.openhome;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Data {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String account = request.getParameter("account");
String passwor = request.getParameter("passwor");
}
public int InsertData() throws ClassNotFoundException, SQLException {
String conUrl = "jdbc:sqlserver://portNumber:1433;serverName=VIOD;databaseName=viod;user=sa;password=02156109;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(conUrl);
PreparedStatement ps;
// database code here
try {
String sql="INSERT INTO a (account,passwor) VALUES (account,passwor)";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, "account");//第一個?要插入的值
pstmt.setString(2, "passwor");//第二個?要插入的值
pstmt.executeUpdate();
pstmt.close();
con.close();
}catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}
String sql="INSERT INTO a (account,passwor) VALUES (account,passwor)";
這句是否有點問題?
多數是 INSERT INTO a (account,passwor) VALUES (?,?)
(c# 及其他 language 都好像這樣寫 prepared statement)
前又是 (account,passwor)
values後又是 (account,passwor)
這樣不是做成 coding 意思模糊不清....?