Created
May 15, 2013 23:14
-
-
Save symtkn/5588176 to your computer and use it in GitHub Desktop.
DAO connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package business; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
public class ProjeDAO { | |
protected String connectionURL = "jdbc:mysql://localhost:3306/uyeler"; | |
public int control(ProjeBean projeBean) throws Exception{ | |
Connection conn = null; | |
PreparedStatement pstmt = null; | |
ResultSet rs = null; | |
String quest = "select * from uye where Adi = ? AND password = ? "; | |
String userName = null; | |
String userPassword = null; | |
try { | |
Class.forName("com.mysql.jdbc.Driver").newInstance(); | |
conn = DriverManager.getConnection(connectionURL, "root", "symtkn"); | |
pstmt = conn.prepareStatement(quest); | |
pstmt.setString(1, projeBean.getAdi()); | |
pstmt.setString(2, projeBean.getPassword()); | |
rs = pstmt.executeQuery(); | |
while (rs.next()) { | |
userName = rs.getString("Adi"); | |
userPassword = rs.getString("password"); | |
} | |
if(userName == null && userPassword == null){ | |
return 0; | |
} | |
} catch (Exception e) { | |
throw e; | |
}finally { | |
try { | |
pstmt.close(); | |
} catch (Exception e2) { | |
} | |
try { | |
conn.close(); | |
} catch (Exception e2) { | |
} | |
} | |
return 1; | |
} | |
public ProjeBean insertProjeBean(ProjeBean projeBean) throws Exception{ | |
Connection conn = null; | |
PreparedStatement pstmt = null; | |
String sqlStr = "insert into uye(Adi, Soyadi, password, eposta)"; | |
sqlStr += "values(?, ?, ?, ?)"; | |
try { | |
Class.forName("com.mysql.jdbc.Driver").newInstance(); | |
conn = DriverManager.getConnection(connectionURL, "root", "symtkn"); | |
if(control(projeBean) == 0){ | |
pstmt = conn.prepareStatement(sqlStr); | |
pstmt.setString(1, projeBean.getAdi()); | |
pstmt.setString(2, projeBean.getSoyadi()); | |
pstmt.setString(3, projeBean.getPassword()); | |
pstmt.setString(4, projeBean.getEposta()); | |
pstmt.executeUpdate(); | |
} | |
} catch (Exception e) { | |
throw e; | |
}finally { | |
try { | |
pstmt.close(); | |
} catch (Exception e2) { | |
} | |
try { | |
conn.close(); | |
} catch (Exception e2) { | |
} | |
} | |
return projeBean; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment