forked from charliecat22/hutubill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5707d8d
Showing
52 changed files
with
2,424 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="lib" path="E:/迅雷下载/how2j/Swing样式大全-全56种经典/Swing样式大全(全56种经典)/5种经典的Alloy和liquidlnf/liquidlnf.jar"/> | ||
<classpathentry kind="lib" path="libs/chart.jar"/> | ||
<classpathentry kind="lib" path="libs/swingx-core-1.6.2.jar"/> | ||
<classpathentry kind="lib" path="libs/mysql-connector-java-5.0.8-bin.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>hutibill</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package dao; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import entity.Category; | ||
import util.DBUtil; | ||
|
||
public class CategoryDAO { | ||
|
||
public int getTotal() { | ||
int total = 0; | ||
try (Connection c = DBUtil.getConnection();Statement s = c.createStatement();){ | ||
String sql = "select count(*) from category"; | ||
ResultSet rs = s.executeQuery(sql); | ||
while(rs.next()){ | ||
total = rs.getInt(1); | ||
} | ||
} catch (SQLException e) { | ||
// TODO: handle exception | ||
e.printStackTrace(); | ||
} | ||
return total; | ||
} | ||
|
||
|
||
public void add(Category category) { | ||
|
||
String sql = "insert into category values(null,?)"; | ||
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { | ||
|
||
ps.setString(1, category.name); | ||
|
||
ps.execute(); | ||
|
||
ResultSet rs = ps.getGeneratedKeys(); | ||
if (rs.next()) { | ||
int id = rs.getInt(1); | ||
category.id = id; | ||
} | ||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void update(Category category) { | ||
|
||
String sql = "update category set name= ? where id = ?"; | ||
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { | ||
|
||
ps.setString(1, category.name); | ||
ps.setInt(2, category.id); | ||
|
||
ps.execute(); | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
public void delete(int id) { | ||
|
||
try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { | ||
|
||
String sql = "delete from category where id = " + id; | ||
|
||
s.execute(sql); | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public Category get(int id) { | ||
Category category = null; | ||
|
||
try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { | ||
|
||
String sql = "select * from category where id = " + id; | ||
|
||
ResultSet rs = s.executeQuery(sql); | ||
|
||
if (rs.next()) { | ||
category = new Category(); | ||
String name = rs.getString(2); | ||
category.name = name; | ||
category.id = id; | ||
} | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
return category; | ||
} | ||
|
||
public List<Category> list() { | ||
return list(0, Short.MAX_VALUE); | ||
} | ||
|
||
public List<Category> list(int start, int count) { | ||
List<Category> categorys = new ArrayList<Category>(); | ||
|
||
String sql = "select * from category order by id desc limit ?,? "; | ||
|
||
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { | ||
|
||
ps.setInt(1, start); | ||
ps.setInt(2, count); | ||
|
||
ResultSet rs = ps.executeQuery(); | ||
|
||
while (rs.next()) { | ||
Category category = new Category(); | ||
int id = rs.getInt(1); | ||
String name = rs.getString(2); | ||
category.id = id; | ||
category.name = name; | ||
categorys.add(category); | ||
} | ||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
return categorys; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package dao; | ||
|
||
import java.sql.Connection; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import entity.Config; | ||
import util.DBUtil; | ||
|
||
public class ConfigDAO { | ||
|
||
public int getTotal() { | ||
int total = 0; | ||
try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { | ||
|
||
String sql = "select count(*) from config"; | ||
|
||
ResultSet rs = s.executeQuery(sql); | ||
while (rs.next()) { | ||
total = rs.getInt(1); | ||
} | ||
|
||
System.out.println("total:" + total); | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
return total; | ||
} | ||
|
||
public void add(Config config) { | ||
|
||
String sql = "insert into config values(null,?,?)"; | ||
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { | ||
ps.setString(1, config.key); | ||
ps.setString(2, config.value); | ||
ps.execute(); | ||
ResultSet rs = ps.getGeneratedKeys(); | ||
if (rs.next()) { | ||
int id = rs.getInt(1); | ||
config.id = id; | ||
} | ||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void update(Config config) { | ||
|
||
String sql = "update config set key_= ?, value=? where id = ?"; | ||
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { | ||
|
||
ps.setString(1, config.key); | ||
ps.setString(2, config.value); | ||
ps.setInt(3, config.id); | ||
|
||
ps.execute(); | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
public void delete(int id) { | ||
|
||
try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { | ||
|
||
String sql = "delete from config where id = " + id; | ||
|
||
s.execute(sql); | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public Config get(int id) { | ||
Config config = null; | ||
|
||
try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { | ||
|
||
String sql = "select * from config where id = " + id; | ||
|
||
ResultSet rs = s.executeQuery(sql); | ||
|
||
if (rs.next()) { | ||
config = new Config(); | ||
String key = rs.getString("key_"); | ||
String value = rs.getString("value"); | ||
config.key = key; | ||
config.value = value; | ||
config.id = id; | ||
} | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
return config; | ||
} | ||
|
||
public List<Config> list() { | ||
return list(0, Short.MAX_VALUE); | ||
} | ||
|
||
public List<Config> list(int start, int count) { | ||
List<Config> configs = new ArrayList<Config>(); | ||
|
||
String sql = "select * from config order by id desc limit ?,? "; | ||
|
||
try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { | ||
|
||
ps.setInt(1, start); | ||
ps.setInt(2, count); | ||
|
||
ResultSet rs = ps.executeQuery(); | ||
|
||
while (rs.next()) { | ||
Config config = new Config(); | ||
int id = rs.getInt(1); | ||
String key = rs.getString("key_"); | ||
String value = rs.getString("value"); | ||
config.id = id; | ||
config.key = key; | ||
config.value = value; | ||
configs.add(config); | ||
} | ||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
return configs; | ||
} | ||
|
||
public Config getByKey(String key) { | ||
Config config = null; | ||
String sql = "select * from config where key_ = ?" ; | ||
try (Connection c = DBUtil.getConnection(); | ||
PreparedStatement ps = c.prepareStatement(sql); | ||
) { | ||
|
||
ps.setString(1, key); | ||
ResultSet rs =ps.executeQuery(); | ||
|
||
if (rs.next()) { | ||
config = new Config(); | ||
int id = rs.getInt("id"); | ||
String value = rs.getString("value"); | ||
config.key = key; | ||
config.value = value; | ||
config.id = id; | ||
} | ||
|
||
} catch (SQLException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
return config; | ||
} | ||
|
||
} |
Oops, something went wrong.