자바좀 알려주세요ㅜㅜㅜ
-
게시물 수정 , 삭제는 로그인 필요
DB가 우선
use uml;
create table loan (
id char(30) not null,
bookname char(50) not null,
author char(40) not null,
constraint loan primary key(id,bookname,author));
insert into loan values("gPqls","연의 편지","조현아");
insert into loan values("wldms","숨","테드 창");
insert into loan values("wlgP","인소의 법칙","유한려");
insert into loan values("rudtjs","돈의 역사","홍춘욱");
insert into loan values("rudtjs","인소의 법칙","유한려");
이구요
제가 DB연결해서 삭제할려고 하는데
void apply_cancel(String id, String title, String author) {
Connection conn = null;
Statement stmt = null;
ResultSet rs;
System.out.print("테이블 접속 : \n");
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/UML?useSSL=false","root","apmsetup");
author = new String(rs.getString("author").getBytes("ISO-8859-1"));;
id = rs.getString("userid");
title = new String(rs.getString("bookname").getBytes("ISO-8859-1"));
String SQL = "delete from loan where id="+id+"";
int rss = stmt.executeUpdate(SQL);
stmt.close();
conn.close();
}
catch(Exception e) {
System.out.println("데이터베이스 연결 실패"+e);
}
finally { // 예외가 있든 없든 무조건 실행
try {
if(stmt!=null) {
stmt.close();
}
if(conn != null) conn.close();
}catch(SQLException e) {
System.out.println("SQL 실행 에러");
}
}
}
근데 이걸하면 DB연결이 안된다고 뜨네요ㅜㅜㅜ 어떻게 해야될까요??ㅜㅜㅜ
DB가 우선
use uml;
create table loan (
id char(30) not null,
bookname char(50) not null,
author char(40) not null,
constraint loan primary key(id,bookname,author));
insert into loan values("gPqls","연의 편지","조현아");
insert into loan values("wldms","숨","테드 창");
insert into loan values("wlgP","인소의 법칙","유한려");
insert into loan values("rudtjs","돈의 역사","홍춘욱");
insert into loan values("rudtjs","인소의 법칙","유한려");
이구요
제가 DB연결해서 삭제할려고 하는데
void apply_cancel(String id, String title, String author) {
Connection conn = null;
Statement stmt = null;
ResultSet rs;
System.out.print("테이블 접속 : \n");
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/UML?useSSL=false","root","apmsetup");
author = new String(rs.getString("author").getBytes("ISO-8859-1"));;
id = rs.getString("userid");
title = new String(rs.getString("bookname").getBytes("ISO-8859-1"));
String SQL = "delete from loan where id="+id+"";
int rss = stmt.executeUpdate(SQL);
stmt.close();
conn.close();
}
catch(Exception e) {
System.out.println("데이터베이스 연결 실패"+e);
}
finally { // 예외가 있든 없든 무조건 실행
try {
if(stmt!=null) {
stmt.close();
}
if(conn != null) conn.close();
}catch(SQLException e) {
System.out.println("SQL 실행 에러");
}
}
}
근데 이걸하면 DB연결이 안된다고 뜨네요ㅜㅜㅜ 어떻게 해야될까요??ㅜㅜㅜ