Java Code Examples for java.sql.SQLException.printStackTrace()

The following are Jave code examples for showing how to use printStackTrace() of the java.sql.SQLException class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: UtilsMaven   File: DBUtils.java   View Source Code Vote up 7 votes
/**
 * 传入的SQL语句只能是INSERT,DELETE,UPDATE和DDL语句
 *
 * @param sql 相应SQL语句
 * @param arg 传入的占位符的参数
 */
public static void update(String sql, Object... arg) {
    Connection connection = JDBCUtils.getConnection();
    PreparedStatement ps = null;
    try {
        ps = connection.prepareStatement(sql);
        for (int i = 0; i < arg.length; i++) {
            ps.setObject(i + 1, arg[i]);
        }
        ps.executeUpdate();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    JDBCUtils.release(ps, connection);
}
 
Example 2
Project: spr   File: SqlDelete.java   View Source Code Vote up 7 votes
public static void deleteZonaGeografica(String id, String tipo_zona_geografica_id){
 	 Connection conect=ConnectionConfiguration.conectar();
 	 Statement statement = null;
 String 							query = "delete from zona_geografica ";
 //if (id!="")						query+= "id=\""+id+"\", ";
 /*if (nombre!="")					query+= "nombre=\""+nombre+"\", ";
 if (descripcion!="")				query+= "descripcion=\""+descripcion+"\", ";
 if (abrev!="")						query+= "abrev=\""+abrev+"\", ";
 //if (tipo_zona_geografica_id!="")	query+= "tipo_zona_geografica_id=\""+tipo_zona_geografica_id+"\", ";
 if (cod_geo_unif!="")				query+= "cod_geo_unif=\""+cod_geo_unif+"\", ";
 query = query.substring(0, query.length()-2);*/
 query+="where id="+id+" and tipo_zona_geografica_id="+tipo_zona_geografica_id;
		
try {
	statement=conect.createStatement();
	statement.execute(query);
    conect.close();
} catch (SQLException e) {e.printStackTrace();}
 }
 
Example 3
Project: spr   File: SqlUpdates.java   View Source Code Vote up 6 votes
public static void updateEjeEstrategico(String id, String nombre,
		String descripcion, String plan_id) {
	Connection conect = ConnectionConfiguration.conectar();
	Statement statement = null;
	String query = "update eje_estrategico set ";
	// if (id!="") query+= "id=\""+id+"\", ";
	if (nombre != "")
		query += "nombre=\"" + nombre + "\", ";
	if (descripcion != "")
		query += "descripcion=\"" + descripcion + "\", ";
	// if (plan_id!="") query+= "plan_id=\""+plan_id+"\", ";
	query = query.substring(0, query.length() - 2);
	query += "where id =" + id + " and plan_id=" + plan_id;

	try {
		statement = conect.createStatement();
		statement.execute(query);
		conect.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
Example 4
Project: ZhihuQuestionsSpider   File: Storer.java   View Source Code Vote up 6 votes
public void store(Result result){
    Pattern pattern1 = Pattern.compile("https://www.zhihu.com/question/\\d+");
    if(pattern1.matcher(result.getPage().getRequest().getUrl()).matches()){
        Question question = (Question) result.getData("data");
        try {
            Connection connection = DBUtil.getConnection();
            PreparedStatement statement = connection.prepareStatement("insert into question(question_name,question_url,followers,browseNum) values (?,?,?,?)");
            statement.setString(1,question.getQuestionName());
            statement.setString(2,question.getQuestionUrl());
            statement.setInt(3,question.getFollowers());
            statement.setInt(4,question.getBrowseNum());
            statement.executeUpdate();
            statement.close();;
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
 
Example 5
Project: spr   File: SqlHelper.java   View Source Code Vote up 6 votes
public static void insertLineasTransversales(int id, String nombre, String descripcion, int plan){
 	 Connection conect=conectar();
 String query = " insert into linea_transversal (id, nombre, descripcion,plan)"
	        + " values (?,?,?,?)";
try {
	
	PreparedStatement preparedStmt;
	preparedStmt = conect.prepareStatement(query);
	
	preparedStmt.setInt (1, id);
	preparedStmt.setString (2, nombre);
	preparedStmt.setString (3, descripcion);
	preparedStmt.setInt (4, plan);
	preparedStmt.execute();
    conect.close();
} catch (SQLException e) {e.printStackTrace();}
 }
 
Example 6
Project: spr   File: SqlInserts.java   View Source Code Vote up 6 votes
public static void insertModuloHasPermiso(ModuloHasPermiso moduloHasPermiso, String usuarioResponsable){
	try {
		Connection conn=ConnectionConfiguration.conectar();
	   	
		String query = " insert into modulo_has_permiso (role_id,modulo_id,permiso_id, usuario_responsable)"
		+ " values (?, ?, ?, ?)";
		
		PreparedStatement insert = conn.prepareStatement(query);
		
		insert.setInt (1, moduloHasPermiso.getRole_id());
		insert.setInt (2, moduloHasPermiso.getModulo_id());
		insert.setInt (3, moduloHasPermiso.getPermiso_id());
		insert.setString (4, usuarioResponsable);
							
		insert.execute();
		   
		conn.close();
	} catch (SQLException e) {e.printStackTrace();}
		
}
 
Example 7
Project: spr   File: SqlUpdates.java   View Source Code Vote up 6 votes
public static void updateTipoZonaGeografica(String id, String nombre,
		String descipcion) {
	Connection conect = ConnectionConfiguration.conectar();
	Statement statement = null;
	String query = "update tipo_zona_geografica set ";
	// if (id!="") query+= "id=\""+id+"\", ";
	if (nombre != "")
		query += "nombre=\"" + nombre + "\", ";
	if (descipcion != "")
		query += "descipcion=\"" + descipcion + "\", ";
	query = query.substring(0, query.length() - 2);
	query += "where id=" + id;

	try {
		statement = conect.createStatement();
		statement.execute(query);
		conect.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
Example 8
Project: fwm   File: TemplateTabController.java   View Source Code Vote up 6 votes
public void simpleSave() {
	getAllTexts();
	if(tabHead.getText()!=null && !tabHead.getText().equals(""))
	{
		// pass
	}
	else {
		log.debug("can't save, no name");
		App.getMainController().addStatus("Unable to save without a name.");
		return;
	}
	try{
		Backend.getTemplateDao().saveFullTemplate(template);
		log.debug("Save successfull!");
		log.debug("template id: " + template.getID());
		App.getMainController().addStatus("Successfully saved base Template " + template.getName() + " ID: " + template.getID());
	}catch(SQLException e){
		log.error(e);
		e.printStackTrace();
	}
}
 
Example 9
Project: spr   File: SqlDelete.java   View Source Code Vote up 5 votes
public static boolean deletePrograma(Programa objeto){
	try {
		Connection conect=ConnectionConfiguration.conectar();
		String query = "update programa set borrado= ? ";	
		PreparedStatement update = null;
		objeto.changeBorrado();
	  	 
		query+=" where id = ? "; 
		
		update.execute(query);
	    conect.close();
	    return true;
	 } catch (SQLException e) {e.printStackTrace(); return false;}
}
 
Example 10
Project: NetworkAnalytics   File: DataManager.java   View Source Code Vote up 5 votes
public void init() {
    try (Connection c = sql.getConnection()) {
        try (PreparedStatement ps = c.prepareStatement(CREATE_TABLE)) {
            ps.execute();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 11
Project: JITRAX   File: DatabaseComparator.java   View Source Code Vote up 5 votes
public DatabaseComparator(Database aDatabase, Connection aDbmsConnection) {
	database = aDatabase;
	dbmsConnection = aDbmsConnection;
	queriesForUpdate = new ArrayList<String>();
	localTablesOnDbms = new ArrayList<Table>();
	
	try {
		databaseMetadata = getDbmsConnection().getMetaData();
		tablesResultSet = databaseMetadata.getTables(null, null, null, new String[] {"TABLE"});
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
Example 12
Project: mycat-src-1.6.1-RELEASE   File: StandBatchInsertTest.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
	Connection theCon = null;
	try {
		theCon = BaseSQLExeTest.getCon(args);
		testJDBCBatchInsert(theCon);
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		BaseSQLExeTest.closeCon(theCon);
	}
}
 
Example 13
Project: tcp   File: SqlSelects.java   View Source Code Vote up 5 votes
public static List<UnidadMedida> selectUnidadMedida() throws SQLException{
Connection conect=ConnectionConfiguration.conectar();
String query = " select * from unidad_medida ORDER BY descripcion";

Statement statement = null;
ResultSet rs=null;
List<UnidadMedida> objetos = new ArrayList<UnidadMedida>();

try {
	statement = conect.createStatement();
	rs=statement.executeQuery(query);
	while(rs.next()){
		UnidadMedida objeto = new UnidadMedida();

		objeto.setId(rs.getInt("id"));
		objeto.setNombre(rs.getString("nombre"));
		objeto.setDescripcion(rs.getString("descripcion"));
		objeto.setSigla(rs.getString("sigla"));
		objeto.setBorrado(rs.getBoolean("borrado"));

		objetos.add(objeto);
	}
}
catch (SQLException e) {e.printStackTrace();}
finally{
	if (statement != null) {statement.close();}
	if (conect != null) {conect.close();}
}
return objetos; 
}
 
Example 14
Project: SuperMarketManageSystem   File: JinHuoTuiHuo.java   View Source Code Vote up 5 votes
private void initSpBox() {
	List list = new ArrayList();
	ResultSet set = Dao.query("select * from tb_kucun where "
			+ "id in(select id from tb_spinfo where gysName='"
			+ gys.getSelectedItem() + "')");
	sp.removeAllItems();
	sp.addItem(new TbKucun());
	for (int i = 0; table != null && i < table.getRowCount(); i++) {
		TbKucun tmpInfo = (TbKucun) table.getValueAt(i, 0);
		if (tmpInfo != null && tmpInfo.getId() != null)
			list.add(tmpInfo.getId());
	}
	try {
		while (set.next()) {
			TbKucun kucun = new TbKucun();
			kucun.setId(set.getString("id").trim());
			// ���������Դ���ͬ����Ʒ����Ʒ�������оͲ��ٰ�������Ʒ
			if (list.contains(kucun.getId()))
				continue;
			kucun.setSpname(set.getString("spname").trim());
			kucun.setCd(set.getString("cd").trim());
			kucun.setJc(set.getString("jc").trim());
			kucun.setDw(set.getString("dw").trim());
			kucun.setGg(set.getString("gg").trim());
			kucun.setBz(set.getString("bz").trim());
			kucun.setDj(Double.valueOf(set.getString("dj").trim()));
			kucun.setKcsl(Integer.valueOf(set.getString("kcsl").trim()));
			sp.addItem(kucun);
		}
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
Example 15
Project: parabuild-ci   File: TestSql.java   View Source Code Vote up 5 votes
public void testAny() {

        try {
            String ddl =
                "drop table PRICE_RELATE_USER_ORDER_V2 if exists;"
                + "create table PRICE_RELATE_USER_ORDER_V2 "
                + "(ID_ORDER_V2 BIGINT, ID_USER NUMERIC, DATE_CREATE TIMESTAMP)";
            String sql = "insert into PRICE_RELATE_USER_ORDER_V2 "
                         + "(ID_ORDER_V2, ID_USER, DATE_CREATE) " + "values "
                         + "(?, ?, ?)";
            Statement st = connection.createStatement();

            st.execute(ddl);

            PreparedStatement ps = connection.prepareStatement(sql);

            ps.setLong(1, 1);
            ps.setNull(2, Types.NUMERIC);
            ps.setTimestamp(
                3, new java.sql.Timestamp(System.currentTimeMillis()));
            ps.execute();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("TestSql.testAny() error: " + e.getMessage());
        }

        System.out.println("testAny complete");
    }
 
Example 16
Project: hotelbook-JavaWeb   File: LogInfoServiceImpl.java   View Source Code Vote up 5 votes
/**
 * 删除
 *
 * @param logId 主键
 * @return 状态码 1成功 0失败
 */
@Override
public int deleteLogInfo(int logId) {

    LogInfo logInfo = new LogInfo();
    logInfo.setLogId(logId);

    try {
        dao.deleteData(logInfo);
    } catch (SQLException e) {
        e.printStackTrace();
        return 0;
    }
    return 1;
}
 
Example 17
Project: spr   File: SqlUpdates.java   View Source Code Vote up 5 votes
public static boolean updateJustificacion(
		Justificacion justificacion,
		String usuarioResponsable) {
	try {
		Connection conect = ConnectionConfiguration.conectar();

		String query = "update justificacion set ";
		PreparedStatement update = null;

		if (justificacion.getDescripcion() != "") {
			query += " descripcion = ?, ";
		}
		{
			query += " usuario_responsable = ?, ";
		}

		query = query.substring(0, query.length() - 2);
		query += " where id = ?";

		int cantCampos = 0;
		update = conect.prepareStatement(query);

		if (justificacion.getDescripcion() != "") {
			cantCampos++;
			update.setString(cantCampos, justificacion.getDescripcion());
		}
		cantCampos++;
		update.setString(cantCampos, usuarioResponsable);

		cantCampos++;
		update.setInt(cantCampos, justificacion.getId());

		update.execute();
		conect.close();
		return true;
	} catch (SQLException e) {
		e.printStackTrace();
		return false;
	}
}
 
Example 18
Project: hotelbook-JavaWeb   File: OrderInfoServiceImpl.java   View Source Code Vote up 5 votes
@Override
public int updateOrderInfo(OrderInfo orderInfo) {
    try {
        dao.updateData(orderInfo);
    } catch (SQLException e) {
        System.out.println(e.getErrorCode() + e.getMessage());
        e.printStackTrace();
        return -1;
    }
    return 1;
}
 
Example 19
Project: iDataBaseConnection   File: DataBase.java   View Source Code Vote up 5 votes
@Override
public int exeSQLInsert(String sql) {
	// TODO Auto-generated method stub
	ConnectionObject conn = ConnectionManager.borrowConnectionObject(connInfo);
	try 
	{
		Statement stat = conn.getConnection().createStatement();
		//stat.executeUpdate(sql);
		int autoGeneratedKeys = 0;
		stat.executeUpdate(sql);
		ResultSet rs = stat.getGeneratedKeys();
		if(rs.next())
		{
			autoGeneratedKeys = rs.getInt(1);
		}
		stat.close();
		return autoGeneratedKeys;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		DBCException.logException(DBCException.E_SQL, e);
		return 0;
	}
	finally
	{
		ConnectionManager.returnConnectionObject(conn);
	}
}
 
Example 20
Project: dev-courses   File: TestLobs.java   View Source Code Vote up 4 votes
public void testBlobI() {

        System.out.println("Starting (sub-)test: " + getName());

        try {
            Statement st = connection.createStatement();

            st.executeUpdate("drop table BLOBTEST if exists");
            st.executeUpdate("create table BLOBTEST (BT_BLOB BLOB)");
            System.out.println("Running insert...");

            PreparedStatement insert =
                connection.prepareStatement("insert into BLOBTEST values(?)");

            insert.setBytes(1, new byte[]{});
            insert.executeUpdate();
            System.out.println("Running update...");

            PreparedStatement update = connection.prepareStatement(
                "update BLOBTEST set BT_BLOB = CONCAT(BT_BLOB,?)");

            update.setBytes(1, new byte[] {
                1, 2, 3
            });
            update.executeUpdate();
            System.out.println("Running select...");

            PreparedStatement select =
                connection.prepareStatement("select BT_BLOB from BLOBTEST");
            ResultSet result = select.executeQuery();

            System.out.println("Results: " + result.getFetchSize());

            while (result.next()) {
                byte[] data = result.getBytes(1);
                String s = data == null ? "null"
                                        : String.valueOf(data.length);
                System.out.println("Result: " + s);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            fail("test failure");
        }
    }