JAVA SQL 구문 전송 방식
1106 단어 잡회
다음은 시험 예 를 드 리 겠 습 니 다.
ResultSet resultset=null;
// PreparedStatement
PreparedStatement stmt=null;
//1.
int id=1234;
String sql ="SELECT * FROM TABLE WHERE ID='"+id+"' ";
stmt=connection.prepareStatement(sql);
//
//Timestamp time = new Timestamp(System.currentTimeMillis());
//String sql="SELECT * FROM TABLE WHERE DATEDIFF(DAY,adatetime,'"+time+"')=1";
//stmt=connection.prepareStatement(sql);
//2.
String id="1234";
String sql ="SELECT * FROM TABLE WHERE ID=?";
stmt=connection.prepareStatement(sql);
stmt.setString(1,id); // 1 1 ,
//
//Timestamp time = new Timestamp(System.currentTimeMillis());
//String sql="SELECT * FROM TABLE WHERE DATEDIFF(DAY,adatetime,?)=1";
//stmt=connection.prepareStatement(sql);
//stmt.setTimestamp(1,time);
resultset=stmt.executeQuery();