📄 musicwishdao.java
字号:
package com.singnet.music.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import com.singnet.music.MusicWishInfo;
public class MusicWishDao {
public Connection getConnection() throws Exception {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:/MySqlDS");
Connection conn = null;
Statement stmt = null;
try {
conn = ds.getConnection();
} catch (SQLException sqlEx) {
System.out.println("Error connect to pool.");
}
return conn;
}
public boolean addMusicWishInfo(MusicWishInfo musicWishInfo)
throws Exception {
Connection conn = null;
Statement stmt = null;
boolean re = false;
String str_sql = "";
System.out.print(str_sql);
try {
conn = getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(str_sql);
re = true;
} catch (SQLException e) {
e.printStackTrace();
re = false;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception sqlEx) {
}
}
}
return re;
}
public boolean editMusicWishInfo(MusicWishInfo musicWishInfo)
throws Exception {
Connection conn = null;
Statement stmt = null;
boolean re = false;
String str_sql = " ";
System.out.print(str_sql);
try {
conn = getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(str_sql);
re = true;
} catch (SQLException e) {
e.printStackTrace();
re = false;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception sqlEx) {
}
}
}
return re;
}
public boolean deleteMusicWishInfo(String id) throws Exception {
Connection conn = null;
Statement stmt = null;
boolean re = false;
String str_sql = " delete from musicarea where id="+id+" ";
try {
conn = getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(str_sql);
re = true;
} catch (SQLException e) {
e.printStackTrace();
re = false;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception sqlEx) {
}
}
}
return re;
}
public MusicWishInfo queryMusicWishInfoById(String id) throws Exception {
Connection conn = null;
Statement stmt = null;
MusicWishInfo re = new MusicWishInfo();
String str_sql = " select * from musicwish where id="+id+" ";
ResultSet rs = null;
System.out.print(str_sql);
try {
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(str_sql);
if(rs.next())
{
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception sqlEx) {
}
}
}
return re;
}
public ArrayList queryMusicWishInfo() throws Exception {
Connection conn = null;
Statement stmt = null;
ArrayList re = new ArrayList();
String str_sql = " select * from musicwish";
ResultSet rs = null;
System.out.print(str_sql);
try {
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(str_sql);
while(rs.next())
{
MusicWishInfo m = new MusicWishInfo();
re.add(m);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception sqlEx) {
}
}
}
return re;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -