using maven build tools instead

This commit is contained in:
Sola
2015-11-13 17:33:58 +08:00
parent 2dd27b3524
commit 8959b33a04
17 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package love.sola.netsupport.sql;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
/**
* ***********************************************
* Created by Sola on 2014/8/20.
* Don't modify this source without my agreement
* ***********************************************
*/
public class SQLCore {
public static DataSource ds;
static {
try {
InitialContext ic = new InitialContext();
ds = (DataSource) ic.lookup("java:comp/env/jdbc/netsupport");
ds.setLoginTimeout(3);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void free(Connection conn) {
if (conn != null) try { conn.close(); } catch (SQLException e) { }
}
}

View File

@@ -0,0 +1,14 @@
package love.sola.netsupport.sql;
/**
* ***********************************************
* Created by Sola on 2015/11/10.
* Don't modify this source without my agreement
* ***********************************************
*/
public class TableConfig {
}

View File

@@ -0,0 +1,66 @@
package love.sola.netsupport.sql;
import love.sola.netsupport.enums.ISPType;
import love.sola.netsupport.pojo.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* ***********************************************
* Created by Sola on 2015/11/10.
* Don't modify this source without my agreement
* ***********************************************
*/
public class TableUser extends SQLCore {
public static final String COLUMN_ID = "id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_STUDENT_ID = "studentid";
public static final String COLUMN_NET_ACCOUNT = "netaccount";
public static final String COLUMN_ISP = "isp";
public static final String COLUMN_WECHAT = "wechat";
public static User getUserByName(String name) {
Connection conn = null;
try {
conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement("SELECT * FROM user_info WHERE name=?");
ps.setString(1, name);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return new User(rs.getInt(COLUMN_ID),
rs.getString(COLUMN_NAME),
rs.getLong(COLUMN_STUDENT_ID),
rs.getString(COLUMN_NET_ACCOUNT),
ISPType.fromId(rs.getInt(COLUMN_ISP)),
rs.getString(COLUMN_WECHAT));
}
} catch (SQLException e) {
} finally { free(conn); }
return null;
}
public static User getUserById(int id) {
Connection conn = null;
try {
conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement("SELECT * FROM user_info WHERE id=?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return new User(rs.getInt(COLUMN_ID),
rs.getString(COLUMN_NAME),
rs.getLong(COLUMN_STUDENT_ID),
rs.getString(COLUMN_NET_ACCOUNT),
ISPType.fromId(rs.getInt(COLUMN_ISP)),
rs.getString(COLUMN_WECHAT));
}
} catch (SQLException e) {
} finally { free(conn); }
return null;
}
}