📄 templet.java
字号:
/* * Templet.java * * Created on 2002年4月26日, 上午11:21 */package com.gs.templet;import java.util.*;import com.gs.db.dbimp.*;import com.gs.db.*;import com.gs.util.Cacheable;import com.gs.util.CacheSizes;import java.sql.*;import java.util.Iterator;import java.util.ArrayList;import java.util.Date;/** * * @author Administrator * @version */public class Templet extends Object { private static final String NEXT_ID = "SELECT max(id) FROM templet"; private static final String ADD_TEMPLET = "insert into templet(id,name) values (?,?)"; private static final String UPDATE_TEMPLET = "update templet set name=?,filename=?,color=?,weight=?,height=?,topint=?,leftint=? where id=?"; private int id; private String name; private String file; private String color; private int weight; private int heigth; private int topint; private int leftint; public Templet(String name) { this.name = name; this.id = this.counterID(NEXT_ID); this.add(); } public Templet(int id,String name,String file,String color,int weight,int height,int top,int left) { this.id = id; this.name = name; this.file = file; this.color = color; this.weight = weight; this.heigth = height; this.topint = top; this.leftint = left; } public void setName(String name) { this.name = name; this.update(); } public void setFile(String file) { this.file = file; this.update(); } public void setColor(String cl) { this.color = cl; this.update(); } public void setWeight(int wt) { this.weight = wt; this.update(); } public void setheight(int ht) { this.heigth = ht; this.update(); } public void setTop(int tp) { this.topint = tp; this.update(); } public void setLeft(int lt) { this.leftint = lt; this.update(); } public int getID() { return this.id; } public String getName() { return this.name; } public String getFile() { return this.file; } public String getColor() { return this.color; } public int getWeight() { return this.weight; } public int getHeight() { return this.heigth; } public int getTop() { return this.topint; } public int getLeft() { return this.leftint; } public int counterID(String query){ int currentID = 0; Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(query); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { currentID = rs.getInt(1); currentID = currentID + 1; } else { currentID = 1; } } catch( Exception sqle ) { System.err.println("Error in DbNews:getNextDbID()-" + sqle); sqle.printStackTrace(); } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } return currentID; } } private synchronized void add() { Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(ADD_TEMPLET); pstmt.setInt(1, id); pstmt.setString(2,name); } catch( SQLException sqle ) { System.err.println( "SQLException in DbNews.java:saveToDb(): " + sqle ); sqle.printStackTrace(); } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } } private synchronized void update() { Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(UPDATE_TEMPLET); pstmt.setString(1, name); pstmt.setString(2,file); pstmt.setString(3,color); pstmt.setInt(4,this.weight); pstmt.setInt(5,this.heigth); pstmt.setInt(6,this.topint); pstmt.setInt(7,this.leftint); pstmt.setInt(8,this.id); pstmt.executeUpdate(); } catch( SQLException sqle ) { System.err.println( "SQLException in DbNews.java:saveToDb(): " + sqle ); sqle.printStackTrace(); } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -