1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/*
* DaoPlannedOrder.java
*dfdfdf
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package basic.dao ;
import basic.beans.Action;
import basic.utils.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Date;
import javax.servlet.ServletContext;
/**
*
* @author fabrice
*/
public class ActionsDao
{
private static ActionsDao instance;
private String driver="com.mysql.jdbc.Driver";
private String dbUrl="jdbc:mysql://localhost/lalima";
private String user="root";
private String password="123456";
private Connection cnx;
private PreparedStatement getAllStmt;
private PreparedStatement putStmt;
private String getQuery;
private String putQuery;
/** Creates a new instance of DaoPlannedOrder */
public ActionsDao()
{
putQuery="INSERT INTO tb_planned_orders VALUES (NULL,?,?,?,?,?,?,?)";
getQuery="SELECT * FROM tb_actions";
try
{
Class.forName(driver);
cnx=DriverManager.getConnection(dbUrl,user,password);
getAllStmt=cnx.prepareStatement(getQuery);
putStmt=cnx.prepareStatement(putQuery);
}
catch (ClassNotFoundException e)
{
}
catch (SQLException e)
{
}
}
public static ActionsDao getInstance()
{
if(instance==null)
instance=new ActionsDao();
return instance;
}
public ArrayList getActions()
{
try
{
ResultSet rs;
ArrayList actionsList= new ArrayList();
getAllStmt=cnx.prepareStatement(getQuery);
synchronized (getAllStmt)
{
rs=getAllStmt.executeQuery();
}
while (rs.next())
{
actionsList.add(makeAction(rs));
}
return actionsList;
}
catch (SQLException e)
{
return null;
}
}
public Action makeAction(ResultSet rs)
{
Action a = new Action();
try
{
a.setId(rs.getInt("id"));
a.setModule(rs.getString("module"));
a.setTask(rs.getString("task"));
a.setCmd((Command) rs.getObject("cmd"));
a.setNextPageId(rs.getString("nextpageid"));
}
catch(SQLException e)
{
}
return a;
}
public void put(Action a)
{
try
{
synchronized(putStmt)
{
/*
putStmt.clearParameters();
putStmt.setString(1,a.getOrderNo());
putStmt.setString(2,a.getSearchKey());
putStmt.setInt(3,a.getFrac());
putStmt.setString(4,a.getColor());
putStmt.setDate(5, (java.sql.Date) a.getDueDate());
putStmt.setString(6,a.getProduct());
putStmt.setInt(7,a.getQuantity());
putStmt.executeUpdate();
*/
}
}
catch(SQLException e)
{
}
}
/* Getters and Setters */
public void setGetQuery(String _queryGet)
{
this.getQuery = _queryGet;
}
public String getGetQuery()
{
return getQuery;
}
public String getPutQuery()
{
return putQuery;
}
public void setPutQuery(String putQuery)
{
this.putQuery = putQuery;
}
} |
Partager