Prof. Edwar Saliba Júnior

Size: px
Start display at page:

Download "Prof. Edwar Saliba Júnior"

Transcription

1 1 package Conexao; * 5 Cynthia Lopes 6 Edwar Saliba Júnior 7 8 import java.io.filenotfoundexception; 9 import java.io.ioexception; 10 import java.sql.sqlexception; 11 import java.sql.statement; 12 import java.sql.connection; 13 import java.sql.drivermanager; 14 import java.sql.resultset; 15 import java.io.bufferedreader; 16 import java.io.filereader; 17 import java.util.arraylist; 18 import java.util.logging.level; 19 import java.util.logging.logger; public final class Database { private Access informationdb; private Connection connectiondb; private Statement querydb; private boolean enablemessages; private final String c_database_file = "JSP_Ex02.txt"; private int dbms; // Sistema Gerenciador de Banco de Dados * Este método retorna um número inteiro que corresponde ao Sistema Gerenciador * de Banco de Dados que está sendo tratado pela classe Database. O valor a * ser retornado poderá ser: * 1 - quando o SGBD utilizado for o PostgreSQL e * 2 - quando o SGBD utilizado for o MySQL. public int getdbms() { return dbms; * Este método configura um parâmetro importante para se trabalhar com a * classe Database, nele deve-se escolher entre dois tipos de Sistemas * Gerenciadores de Banco de Dados (PostgreSQL e MySQL). O valor a ser * passado para o parâmetro "sgdb" deverá ser: * 1 - quando o SGBD utilizado for o PostgreSQL e * 2 - quando o SGBD utilizado for o MySQL. dbms public void setdbms(int dbms) { this.dbms = dbms; public Database() throws FileNotFoundException, ClassNotFoundException { FileReader file = new FileReader(c_DATABASE_FILE); BufferedReader reader = new BufferedReader(file); String databasename; databasename = reader.readline(); String password = reader.readline(); String host = reader. r.readline(); reader.close(); file.close(); this.informationdb = new Access(dataBaseName, password, host); this.connectiontodb() (); this.enablemessages = true; // Valor padrão para o atributo é o SGBD PostgreSQL. this.dbms = 1; catch (IOException ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); public Database(String databasename, String password, String host) { this.informationdb = new Access(dataBaseName, password, host); this.connectiontodb() (); this.enablemessages = false; catch (Exception ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); 1.1 of :01:02

2 public Database(Access info) { this.informationdb = info; this.enablemessages = false; * O parâmetro "tipobanco" deve receber: - 1 para PostgreSQL - 2 para MySQL * tipobanco (int) ClassNotFoundException public void connectiontodb() throws ClassNotFoundException { this.startdriver(); connectiondb = DriverManager.getConnection( this.informationdb.geturl(), this.informationdb.getusuario(), this.informationdb.getsenha()); System.out.println("Connection with database '" + this.informationdb. B.getNomeBD() + "' sucess completed."); this.querydb = this.connectiondb. B.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY ); catch (SQLException e) { System.out.println(e.toString( g()); public void startdriver() throws ClassNotFoundException { switch (dbms) { case 1: Class.forName("org.postgresql.Driver"); break; case 2: Class.forName("com.mysql.jdbc.Driver"); public void insertvalues(string tablename, String fieldsnames[], String fieldsvalues[] []) String query; boolean putquotationmarks; putquotationmarks = dbms == 1; query = "INSERT INTO \"" + tablename + "\" ("; query += returnfieldsnames(fieldsnames) + ")"; query += " VALUES("; query += returnvalues(fieldsvalues, true) + ")"; else { query = "INSERT INTO " + tablename + " ("; query += returnfieldsnames(fieldsnames) + ")"; query += " VALUES("; query += returnvalues(fieldsvalues, true) + ")"; this.querydb.execute(query); this.connectiondb.commit(); public void deletevalues(string tablename, String query; query = "DELETE FROM \"" + tablename + "\""; else { query = "DELETE FROM " + tablename + " "; this.querydb.execute(query); 2.1 of :01:02

3 this.connectiondb.commit(); public void updatevalues(string tablename, String fields[], String values[], String query; query = "UPDATE \"" + tablename + "\" SET "; query += this.returnsetvalues(fields, values, true); else { query = "UPDATE " + tablename + " SET "; query += this.returnsetvalues(fields, values, false); this.querydb.execute(query); this.connectiondb.commit(); public boolean existrow(string table, boolean foundrow; String query = "SELECT 1 "; query += " FROM \"" + table + "\""; foundrow = resultset.first(); return (foundrow); public void printselection(string table, String fields[], String condition) query += " FROM \"" + table + "\""; while (resultset.next()) { String print = ""; for (int i = 0; i < fields.length; i++) { print += " " + resultset.getstring(fields[i]) + " \t"; System.out.println(print); public ArrayList selection(string table, boolean putquotationmarksonthefields, String fields[], String condition) { ArrayList resultslist = new ArrayList(); if (putquotationmarksonthefields) s) { else { query += returnvalues(fields, s, putquotationmarksonthefields); query += " FROM " + table; 3.1 of :01:02

4 query += " FROM " + table; resultset.beforefirst(); while (resultset.next()) { String[] row = new String[resultSet.getMetaData().getColumnCount()]; for (int i = 0; i < resultset.getmetadata().getcolumncount(); i++) { row[i] = resultset.getstring(i + 1); resultslist.add(row); catch (SQLException ex) { System.out.println("Exceção SQL: " + ex); return resultslist; public ResultSet selection(string table, String fields[], boolean putquotationmarksonthefields, String condition, boolean pointertofirstrecord) if (putquotationmarksonthefields) { query += " FROM \"" + table + "\""; else { query += " FROM " + table + " "; else { query += returnvalues(fields, putquotationmarksonthefields); query += " FROM " + table; if (pointertofirstrecord) { resultset.next(); return (resultset); public ResultSet selection(string query) resultset.next(); return (resultset); public void printjoinselection(string tables[], String fields[] [], query += " FROM " + returnfieldsnames(tables); for (int i = 0; i < fields.length; i++) { int dotposition = fields[i].indexof('.'); fields[i] = fields[i] i].substring(dotposition + 1, fields[i].length()); while (resultset.next()) { String print = ""; for (int i = 0; i < fields.length; i++) { print += " " + resultset.getstring(fields[i]) + " \t"; 4.1 of :01:02

5 System.out.println(print); public String returnvalues(string values[], boolean putquotationmarks) { String vals = ""; vals += "\'" + values[i] + "\', "; vals += "\'" + values[values.length - 1] + "\'"; else { vals += values[i] + ", "; vals += values[values.length - 1]; return vals; public String returnfieldsnames(string values[]) { boolean putquotationmarks; putquotationmarks = dbms == 1; String vals; vals = "\""; vals += values[i] + "\", \""; vals += values[values.length - 1] + "\""; else { vals = ""; vals += values[i] + ", "; vals += values[values.length - 1]; return vals; public String returnsetvalues(string fields[], String values[] [], boolean putquotationmarks) { String vals = ""; vals += "\"" + fields[i] + "\" = " + (values[i].equals("")? "\'\'" : "\'" + values[ s[i] + "\'") + ", "; else { vals += "" + fields[i] + " = " + (values[i].equals("")? "\'\'" : "\'" + values[ s[i] + "\'") + ", "; vals += "\"" + fields[fields.length - 1] + "\" = " + (values[values.length - 1].equals("")? "\'\'" : "\'" + values[values.length - 1] + "\'"); else { vals += "" + fields[fields.length - 1] + " = " + (values[values.length - 1].equals("")? "\'\'" : "\'" + values[values.length - 1] + "\'"); return vals; * Converte um vetor de inteiros para um formato aceitável por um campo do * tipo "array" do PostgreSQL. * Vetor de Inteiros "'{ val1, val2,... '" public String converttostringarray(int v[] []) { String vetor = ""; 5.1 of :01:02

6 vetor += "{"; for (int i = 0; i < v.length; i++) { if ((i < (v.length - 1)) && (!((i(i > 0) && (String.valueOf(v[i]).equals("0"))))) { vetor += String.valueOf(v[i]) + ","; else { vetor += String.valueOf(v[i]); break; vetor += ""; return (vetor); * Converte um campo do tipo "array" do PostgreSQL (String) num vetor de * inteiros. * "String" - Ex.: {0,80,17,71,13,0 "int []" - Ex.: [0,80,17,71,13,0] public int[] converttointarray(string v) { v = v.trim() (); int vetor[] = new int[v.split(",", -1).length]; int j = 0; String n = ""; for (int i = 0; i < v.length(); i++) { if ((v.charat(i)!= '{') && (v.charat(i)!= '')) { if ((v.charat(i)!= ',') && (v.charat(i)!= ' ')) { n += v.substring(i, i + 1); else { vetor[j++] = Integer.parseInt(n); n = ""; return (vetor); public void closedbconnection() this.connectiondb.close() (); public boolean isenablemessages() { return enablemessages; public void setenablemessages(boolean enablemessages) { this.enablemessages = enablemessages; public void finalize() throws SQLException, Throwable { super.finalize(); closedbconnection(); private Object getfieldvalue(string tablename, String fieldname, boolean putquotationmarks; Object value = null; String fields[] = {fieldname; /* Se o banco não for PostgreSQL, não colocar aspas no campo e tampouco na tabela. putquotationmarks = (dbms == 1); ResultSet rs = selection( n(tablename, fields, putquotationmarks, condition, n, true); if (rs.first()) { value = rs.getobject( t(fieldname); public String getstringfieldvalue(string tables, String fields, String value = ""; if (val!= null) l) { 6.1 of :01:02

7 if (val!= null) l) { value = val.tostring( g(); public int getintfieldvalue(string tables, String fields, String condition) int value = 0; if (val!= null) { value = Integer.valueOf(val.toString()); public float getfloatfieldvalue(string tables, String fields, String condition) float value = 0; if (val!= null) { value = Float.valueOf (val.tostring()); public boolean getbooleanfieldvalue(string tables, String fields, boolean value = false; if (val!= null) { value = Boolean.valueOf(val.toString()); public int getnumberofrowsintable(string table, boolean putquotation) ResultSet rs; if (putquotation) { rs = selection("select count(*) " + " FROM \"" + table + "\""); else { rs = selection("select count(*) " + " FROM " + table); int value = rs.getint(1); return value; 7.1 of :01:02

Prof. Edwar Saliba Júnior

Prof. Edwar Saliba Júnior 2 3 /** 4 * 5 * @author Cynthia Lopes 6 * @author Edwar Saliba Júnior 7 */ 8 import java.io. o.filenotfoundexception; 9 import java.io. o.ioexception; 10 import java.sql.sqlexception; 11 import java.sql.statement;

More information

SQream Connector JDBC SQream Technologies Version 2.9.3

SQream Connector JDBC SQream Technologies Version 2.9.3 SQream Connector JDBC 2.9.3 SQream Technologies 2019-03-27 Version 2.9.3 Table of Contents The SQream JDBC Connector - Overview...................................................... 1 1. API Reference............................................................................

More information

Learn Sphinx Documentation Documentation

Learn Sphinx Documentation Documentation Learn Sphinx Documentation Documentation Release 0.0.1 Lucas Simon Rodrigues Magalhaes January 31, 2014 Contents 1 Negrito e italico 1 2 Listas 3 3 Titulos 5 4 H1 Titulo 7 4.1 H2 Sub-Titulo.............................................

More information

WEB SERVICES EXAMPLE 2

WEB SERVICES EXAMPLE 2 INTERNATIONAL UNIVERSITY HCMC PROGRAMMING METHODOLOGY NONG LAM UNIVERSITY Instructor: Dr. Le Thanh Sach FACULTY OF IT WEBSITE SPECIAL SUBJECT Student-id: Instructor: LeMITM04015 Nhat Tung Course: IT.503

More information

Fundamentos de programação

Fundamentos de programação Fundamentos de programação Tratamento de exceções Edson Moreno edson.moreno@pucrs.br http://www.inf.pucrs.br/~emoreno Exception Handling There are two aspects to dealing with run-time program errors: 1)

More information

Servlet 5.1 JDBC 5.2 JDBC

Servlet 5.1 JDBC 5.2 JDBC 5 Servlet Java 5.1 JDBC JDBC Java DataBase Connectivity Java API JDBC Java Oracle, PostgreSQL, MySQL Java JDBC Servlet OpenOffice.org ver. 2.0 HSQLDB HSQLDB 100% Java HSQLDB SQL 5.2 JDBC Java 1. JDBC 2.

More information

EJB - ACCESS DATABASE

EJB - ACCESS DATABASE EJB - ACCESS DATABASE http://www.tutorialspoint.com/ejb/ejb_access_database.htm Copyright tutorialspoint.com EJB 3.0, persistence mechanism is used to access the database in which container manages the

More information

Exception Handling CSCI 201 Principles of Software Development

Exception Handling CSCI 201 Principles of Software Development Exception Handling CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu Outline Program USC CSCI 201L 2/19 Exception Handling An exception is an indication of a problem

More information

Assignment -3 Source Code. Student.java

Assignment -3 Source Code. Student.java import java.io.serializable; Assignment -3 Source Code Student.java public class Student implements Serializable{ public int rollno; public String name; public double marks; public Student(int rollno,

More information

Programming a Bank Database. We ll store the information in two tables: INTEGER DECIMAL(10, 2)

Programming a Bank Database. We ll store the information in two tables: INTEGER DECIMAL(10, 2) WE1 W o r k e d E x a m p l e 2 2.1 Programming a Bank Database In this Worked Example, we will develop a complete database program. We will reimplement the ATM simulation of Chapter 12, storing the customer

More information

while (rs.next()) { String[] temp_array = {"","",""}; int prodid = rs.getint(1); temp_array[0] = ""+prodid;

while (rs.next()) { String[] temp_array = {,,}; int prodid = rs.getint(1); temp_array[0] = +prodid; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import java.util.arraylist; import java.util.scanner; public

More information

1. PhP Project. Create a new PhP Project as shown below and click next

1. PhP Project. Create a new PhP Project as shown below and click next 1. PhP Project Create a new PhP Project as shown below and click next 1 Choose Local Web Site (Apache 24 needs to be installed) Project URL is http://localhost/projectname Then, click next We do not use

More information

CreateServlet.java

CreateServlet.java Classes in OBAAS 1.2: -------------------- The package name is pack_bank. Create this package in java source of your project. Create classes as per the class names provided here. You can then copy the

More information

HL7 FHIR Data Consolidation Tool

HL7 FHIR Data Consolidation Tool WHITE PAPER HL7 FHIR Data Consolidation Tool What is HL7 FHIR? HL7 FHIR or FHIR (Fast Healthcare Interoperability Resources pronounced as "Fire") is a part of the Medical Healthcare information ecosystem

More information

CN208 Introduction to Computer Programming

CN208 Introduction to Computer Programming CN208 Introduction to Computer Programming Lecture #11 Streams (Continued) Pimarn Apipattanamontre Email: pimarn@pimarn.com 1 The Object Class The Object class is the direct or indirect superclass of every

More information

To create a view for students, staffs and courses in your departments using servlet/jsp.

To create a view for students, staffs and courses in your departments using servlet/jsp. Aim To create a view for students, staffs and courses in your departments using servlet/jsp. Software Requirements: Java IDE Database Server JDK1.6 Netbean 6.9/Eclipse MySQL Tomcat/Glassfish Login Form

More information

DB I. 1 Dr. Ahmed ElShafee, Java course

DB I. 1 Dr. Ahmed ElShafee, Java course Lecture (15) DB I Dr. Ahmed ElShafee 1 Dr. Ahmed ElShafee, Java course Agenda 2 Dr. Ahmed ElShafee, Java course Introduction Java uses something called JDBC (Java Database Connectivity) to connect to databases.

More information

Projeto de Software / Programação 3 Tratamento de Exceções. Baldoino Fonseca/Márcio Ribeiro

Projeto de Software / Programação 3 Tratamento de Exceções. Baldoino Fonseca/Márcio Ribeiro Projeto de Software / Programação 3 Tratamento de Exceções Baldoino Fonseca/Márcio Ribeiro baldoino@ic.ufal.br What can go wrong?! result = n1 / n2; In the following slides: 1) Analyze the code; 2) read

More information

UNIT-3 Java Database Client/Server

UNIT-3 Java Database Client/Server UNIT-3 Java Database Client/Server TOPICS TO BE COVERED 3.1 Client-Server Design: Two-Tier Database Design, Three-Tier Database Design 3.2 The JDBC API: The API Components, Database Creation, table creation

More information

ANN exercise session

ANN exercise session ANN exercise session In this exercise session, you will read an external file with Iris flowers and create an internal database in Java as it was done in previous exercise session. A new file contains

More information

Chapter 16: Databases

Chapter 16: Databases Chapter 16: Databases Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 16 discusses the following main topics: Introduction to Database

More information

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this. CS 201, Fall 2013 Oct 2nd Exam 1 Name: Question 1. [5 points] What output is printed by the following program (which begins on the left and continues on the right)? public class Q1 { public int x; public

More information

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley CSCI/CMPE 3326 Object-Oriented Programming in Java JDBC Dongchul Kim Department of Computer Science University of Texas Rio Grande Valley Introduction to Database Management Systems Storing data in traditional

More information

Server-side Web Programming

Server-side Web Programming Server-side Web Programming Lecture 13: JDBC Database Programming JDBC Definition Java Database Connectivity (JDBC): set of classes that provide methods to Connect to a database through a database server

More information

Input from Files. Buffered Reader

Input from Files. Buffered Reader Input from Files Buffered Reader Input from files is always text. You can convert it to ints using Integer.parseInt() We use BufferedReaders to minimize the number of reads to the file. The Buffer reads

More information

Oracle Exam 1z0-809 Java SE 8 Programmer II Version: 6.0 [ Total Questions: 128 ]

Oracle Exam 1z0-809 Java SE 8 Programmer II Version: 6.0 [ Total Questions: 128 ] s@lm@n Oracle Exam 1z0-809 Java SE 8 Programmer II Version: 6.0 [ Total Questions: 128 ] Oracle 1z0-809 : Practice Test Question No : 1 Given: public final class IceCream { public void prepare() { public

More information

Complimentary material for the book Software Engineering in the Agile World

Complimentary material for the book Software Engineering in the Agile World Complimentary material for the book Software Engineering in the Agile World (ISBN: 978-93-5300-898-7) published by Amazon, USA (ISBN: 978-1976901751) and Flushing Meadows Publishers, India (ISBN: 978-93-5300-898-7)

More information

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004 1.00/1.001 Introduction to Computers and Engineering Problem Solving Final / December 13, 2004 Name: Email Address: TA: Section: You have 180 minutes to complete this exam. For coding questions, you do

More information

Author - Ashfaque Ahmed

Author - Ashfaque Ahmed Complimentary material for the book Software Engineering in the Agile World (ISBN: 978-1983801570) published by Create Space Independent Publishing Platform, USA Author - Ashfaque Ahmed Technical support

More information

SQL in a Server Environment

SQL in a Server Environment SQL in a Server Environment Vaidė Narváez Computer Information Systems January 13th, 2011 The Three-Tier Architecture Application logic components Copyright c 2009 Pearson Education, Inc. Publishing as

More information

Java Database Connectivity

Java Database Connectivity Java Database Connectivity INTRODUCTION Dr. Syed Imtiyaz Hassan Assistant Professor, Deptt. of CSE, Jamia Hamdard (Deemed to be University), New Delhi, India. s.imtiyaz@jamiahamdard.ac.in Agenda Introduction

More information

SQL and Java. Database Systems Lecture 20 Natasha Alechina

SQL and Java. Database Systems Lecture 20 Natasha Alechina Database Systems Lecture 20 Natasha Alechina In this Lecture SQL in Java SQL from within other Languages SQL, Java, and JDBC For More Information Sun Java tutorial: http://java.sun.com/docs/books/tutorial/jdbc

More information

Visit for more.

Visit  for more. Chapter 6: Database Connectivity Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra, PGT (Comp.Sc.)

More information

C:/Users/zzaier/Documents/NetBeansProjects/WebApplication4/src/java/mainpackage/MainClass.java

C:/Users/zzaier/Documents/NetBeansProjects/WebApplication4/src/java/mainpackage/MainClass.java package mainpackage; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import javax.ws.rs.core.context; import

More information

This lecture. Databases - JDBC I. Application Programs. Database Access End Users

This lecture. Databases - JDBC I. Application Programs. Database Access End Users This lecture Databases - I The lecture starts discussion of how a Java-based application program connects to a database using. (GF Royle 2006-8, N Spadaccini 2008) Databases - I 1 / 24 (GF Royle 2006-8,

More information

CS221 Lecture: Java Database Connectivity (JDBC)

CS221 Lecture: Java Database Connectivity (JDBC) CS221 Lecture: Java Database Connectivity (JDBC) Objectives: 1. To introduce using JDBC to access a SQL database revised 10/20/14 Materials: 1. Projectable of registration system architecture. 2. JDBC

More information

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text Learning Objectives This module gives an introduction about Java Database

More information

Accessing databases in Java using JDBC

Accessing databases in Java using JDBC Accessing databases in Java using JDBC Introduction JDBC is an API for Java that allows working with relational databases. JDBC offers the possibility to use SQL statements for DDL and DML statements.

More information

An IBM Rational Software TechNote

An IBM Rational Software TechNote Data Driven Testing: How to Create a Data Driven Test with XDE Tester An IBM Rational Software TechNote 1 Creating a Data-Driven Test with XDE Tester By Dr. Gerd Weishaar The samples provided in the advanced

More information

CSE 530A. DAOs and MVC. Washington University Fall 2012

CSE 530A. DAOs and MVC. Washington University Fall 2012 CSE 530A DAOs and MVC Washington University Fall 2012 Model Object Example public class User { private Long id; private String username; private String password; public Long getid() { return id; public

More information

What can go wrong in a Java program while running?

What can go wrong in a Java program while running? Exception Handling See https://docs.oracle.com/javase/tutorial/ essential/exceptions/runtime.html See also other resources available on the module webpage This lecture Summary on polymorphism, multiple

More information

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Database Connection Budditha Hettige Department of Statistics and Computer Science Budditha Hettige 1 From database to Java There are many brands of database: Microsoft

More information

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview COSC 304 Introduction to Database Systems Database Programming Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Database Programming Overview Most user interaction with

More information

Inserting users from SQL data to Active Directory

Inserting users from SQL data to Active Directory 1 Inserting users from SQL data to Active Directory Contents 1. Requirement... 2 2. Prerequisites:... 3 3. Environment used... 3 4. Steps following... 3 5. Parsing the XML file... 5 6. Establishing the

More information

Calling SQL from a host language (Java and Python) Kathleen Durant CS 3200

Calling SQL from a host language (Java and Python) Kathleen Durant CS 3200 Calling SQL from a host language (Java and Python) Kathleen Durant CS 3200 1 SQL code in other programming languages SQL commands can be called from within a host language (e.g., C++ or Java) program.

More information

Studying software design patterns is an effective way to learn from the experience of others

Studying software design patterns is an effective way to learn from the experience of others Studying software design patterns is an effective way to learn from the experience of others Design Pattern allows the requester of a particular action to be decoupled from the object that performs the

More information

Working with Databases and Java

Working with Databases and Java Working with Databases and Java Pedro Contreras Department of Computer Science Royal Holloway, University of London January 30, 2008 Outline Introduction to relational databases Introduction to Structured

More information

Chapter 15. Exception Handling. Chapter Goals. Error Handling. Error Handling. Throwing Exceptions. Throwing Exceptions

Chapter 15. Exception Handling. Chapter Goals. Error Handling. Error Handling. Throwing Exceptions. Throwing Exceptions Chapter 15 Exception Handling Chapter Goals To learn how to throw exceptions To be able to design your own exception classes To understand the difference between checked and unchecked exceptions To learn

More information

SQLite Database. References. Overview. Structured Databases

SQLite Database. References. Overview. Structured Databases SQLite Database References Android Developers Article https://developer.android.com/training/basics/data-storage/databases.html Android SQLite Package Reference https://developer.android.com/reference/android/database/sqlite/package-summary.html

More information

JDBC [Java DataBase Connectivity]

JDBC [Java DataBase Connectivity] JDBC [Java DataBase Connectivity] Introduction Almost all the web applications need to work with the data stored in the databases. JDBC is Java specification that allows the Java programs to access the

More information

Databases 2012 Embedded SQL

Databases 2012 Embedded SQL Databases 2012 Christian S. Jensen Computer Science, Aarhus University SQL is rarely written as ad-hoc queries using the generic SQL interface The typical scenario: client server database SQL is embedded

More information

Tiers (or layers) Separation of concerns

Tiers (or layers) Separation of concerns Tiers (or layers) Separation of concerns Hiding the type of storage from the client class Let s say we have a program that needs to fetch objects from a storage. Should the program have to be concerned

More information

Project Documentation

Project Documentation Project Documentation A JDBC Driver Supporting Data Integration and Evolution Jian Jia Goals University of Iowa, Iowa City, IA jjia@cs.uiowa.edu This project will produce a Unity JDBC Driver that is compliant

More information

Java Database Connectivity (JDBC) 25.1 What is JDBC?

Java Database Connectivity (JDBC) 25.1 What is JDBC? PART 25 Java Database Connectivity (JDBC) 25.1 What is JDBC? JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent connectivity between the Java programming

More information

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004 1.00/1.001 Introduction to Computers and Engineering Problem Solving Final / December 13, 2004 Name: Email Address: TA: Solution Section: You have 180 minutes to complete this exam. For coding questions,

More information

Develop an Enterprise Java Bean for Banking Operations

Develop an Enterprise Java Bean for Banking Operations Develop an Enterprise Java Bean for Banking Operations Aim: Develop a Banking application using EJB3.0 Software and Resources: Software or Resource Version Required NetBeans IDE 6.7, Java version Java

More information

Assignment #3. CS Spring 2015 Due on Saturday, July 25, 2015, 9 AM For instructions on how to submit your assignment check the course website.

Assignment #3. CS Spring 2015 Due on Saturday, July 25, 2015, 9 AM For instructions on how to submit your assignment check the course website. Assignment #3 CS 348 - Spring 2015 Due on Saturday, July 25, 2015, 9 AM For instructions on how to submit your assignment check the course website. 1 CS 348 - Spring 2015 : Assignment #3 QUESTION 1. Question

More information

CS1092: Tutorial Sheet: No 3 Exceptions and Files. Tutor s Guide

CS1092: Tutorial Sheet: No 3 Exceptions and Files. Tutor s Guide CS1092: Tutorial Sheet: No 3 Exceptions and Files Tutor s Guide Preliminary This tutorial sheet requires that you ve read Chapter 15 on Exceptions (CS1081 lectured material), and followed the recent CS1092

More information

BBM 102 Introduction to Programming II Spring Exceptions

BBM 102 Introduction to Programming II Spring Exceptions BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom

More information

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection.

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection. JDBC PROGRAMMING JDBC JDBC Java DataBase Connectivity Useful for database driven applications Standard API for accessing relational databases Compatible with wide range of databases Current Version JDBC

More information

Pieter van den Hombergh. March 25, 2018

Pieter van den Hombergh. March 25, 2018 ergh Fontys Hogeschool voor Techniek en Logistiek March 25, 2018 ergh/fhtenl March 25, 2018 1/25 JDBC JDBC is a Java database connectivity technology (Java Standard Edition platform) from Oracle Corporation.

More information

I/O STREAM (REQUIRED IN THE FINAL)

I/O STREAM (REQUIRED IN THE FINAL) I/O STREAM (REQUIRED IN THE FINAL) STREAM A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents

More information

FILE I/O IN JAVA. Prof. Chris Jermaine

FILE I/O IN JAVA. Prof. Chris Jermaine FILE I/O IN JAVA Prof. Chris Jermaine cmj4@cs.rice.edu 1 Our Simple Java Programs So Far Aside from screen I/O......when they are done, they are gone They have no lasting effect on the world When the program

More information

Lösungsvorschläge zum Übungsblatt 5: Fortgeschrittene Aspekte objektorientierter Programmierung (SS 2007)

Lösungsvorschläge zum Übungsblatt 5: Fortgeschrittene Aspekte objektorientierter Programmierung (SS 2007) Prof. Dr. A. Poetzsch-Heffter Dipl.-Inform. N. Rauch Technische Universität Kaiserslautern Fachbereich Informatik AG Softwaretechnik Lösungsvorschläge zum Übungsblatt 5: Fortgeschrittene Aspekte objektorientierter

More information

Chair of Software Engineering. Java and C# in Depth. Prof. Dr. Bertrand Meyer. Exercise Session 9. Nadia Polikarpova

Chair of Software Engineering. Java and C# in Depth. Prof. Dr. Bertrand Meyer. Exercise Session 9. Nadia Polikarpova Chair of Software Engineering Java and C# in Depth Prof. Dr. Bertrand Meyer Exercise Session 9 Nadia Polikarpova Quiz 1: scrolling a ResultSet (JDBC) How do you assess the following code snippet that iterates

More information

SQL from Applications

SQL from Applications SQL from Applications UVic C SC 370 Dr. Daniel M. German Department of Computer Science June 4, 2003 Version: 1.1.0 6 1 SQL from Applications (1.1.0) CSC 370 dmgerman@uvic.ca Overview Embedded SQL JDBC

More information

Overview. SQL from Applications. Accesing data from an application. Embedded SQL JDBC Stored Procedures. UVic C SC 370, Fall 2002

Overview. SQL from Applications. Accesing data from an application. Embedded SQL JDBC Stored Procedures. UVic C SC 370, Fall 2002 SQL from Applications UVic C SC 370, Fall 2002 Embedded SQL JDBC Stored Procedures Overview Daniel M. German Department of Computer Science University of Victoria October 15, 2002 Version: 1.00 6 1 SQL

More information

Lecture 4: Exceptions. I/O

Lecture 4: Exceptions. I/O Lecture 4: Exceptions. I/O Outline Access control. Class scope Exceptions I/O public class Malicious { public static void main(string[] args) { maliciousmethod(new CreditCard()); } static void maliciousmethod(creditcard

More information

src docs Release Author

src docs Release Author src docs Release 0.8.18 Author September 20, 2018 Contents 1 networkapiclient package 3 1.1 Submodules............................................... 3 1.2 networkapiclient.ambiente module...................................

More information

Döcu Content IBM Notes Domino, DB2 Oracle JDeveloper, WebLogic

Döcu Content IBM Notes Domino, DB2 Oracle JDeveloper, WebLogic Döcu Content IBM Notes Domino, DB2 Oracle JDeveloper, WebLogic Research/Create App Classes +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>> 2015.10.31.9.56.AM Getting IBM Lotus Notes

More information

Chapter 12. File Input and Output. CS180-Recitation

Chapter 12. File Input and Output. CS180-Recitation Chapter 12 File Input and Output CS180-Recitation Reminders Exam2 Wed Nov 5th. 6:30 pm. Project6 Wed Nov 5th. 10:00 pm. Multitasking: The concurrent operation by one central processing unit of two or more

More information

Introduction to Relational Database Management Systems

Introduction to Relational Database Management Systems Introduction to Relational Database Management Systems nikos bikakis bikakis@dblab.ntua.gr dblab NTU Athens Jan 2014 Outline RDBMS History Relational Model Overview RDBMS Overview Integrity Constraints

More information

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server. JDBC Drivers Type 1 What is JDBC Driver? JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server. For example, using JDBC drivers enable you to open database

More information

Formal Methods for Java

Formal Methods for Java Formal Methods for Java Lecture 17: Advanced Key Jochen Hoenicke Software Engineering Albert-Ludwigs-University Freiburg December 21, 2011 Jochen Hoenicke (Software Engineering) Formal Methods for Java

More information

BBM 102 Introduction to Programming II Spring 2017

BBM 102 Introduction to Programming II Spring 2017 BBM 102 Introduction to Programming II Spring 2017 Exceptions Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi Today What is an exception? What is exception handling? Keywords of exception

More information

GPolygon GCompound HashMap

GPolygon GCompound HashMap Five-Minute Review 1. How do we construct a GPolygon object? 2. How does GCompound support decomposition for graphical objects? 3. What does algorithmic complexity mean? 4. Which operations does a HashMap

More information

Do not turn to the next page until the start of the exam.

Do not turn to the next page until the start of the exam. Principles of Java Language with Applications, PIC20a E. Ryu Winter 2017 Final Exam Monday, March 20, 2017 3 hours, 8 questions, 100 points, 11 pages While we don t expect you will need more space than

More information

3) execute() Usage: when you cannot determine whether SQL is an update or query return true if row is returned, use getresultset() to get the

3) execute() Usage: when you cannot determine whether SQL is an update or query return true if row is returned, use getresultset() to get the Agenda Lecture (07) Database connectivity (II) Connecting DB Dr. Ahmed ElShafee 1 Dr. Ahmed ElShafee, ACU Spring 2011, Distributed Systems 2 Dr. Ahmed ElShafee, ACU Spring 2011, Distributed Systems The

More information

First Exam/Second Test 19/6/2010

First Exam/Second Test 19/6/2010 Instituto Superior Técnico Programação Avançada First Exam/Second Test 19/6/2010 Name: Number: Write your number on every page. Your answers should not be longer than the available space. You can use the

More information

Exceptions - Example. Exceptions - Example

Exceptions - Example. Exceptions - Example - Example //precondition: x >= 0 public void sqrt(double x) double root; if (x < 0.0) //What to do? else //compute the square root of x return root; 1 - Example //precondition: x >= 0 public void sqrt(double

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) SQL-Part III & Storing Data: Disks and Files- Part I Lecture 8, February 5, 2014 Mohammad Hammoud Today Last Session: Standard Query Language (SQL)- Part II Today s Session:

More information

Database connectivity (II)

Database connectivity (II) Lecture (07) Database connectivity (II) Dr. Ahmed ElShafee 1 Dr. Ahmed ElShafee, ACU Spring 2011, Distributed Systems Agenda Connecting DB 2 Dr. Ahmed ElShafee, ACU Spring 2011, Distributed Systems The

More information

Introdução às GPUs. Graphics Pipeline. Marcelo Walter UFPE. 3D Application or Game. 3D API: OpenGL or Direct 3D. Vertices

Introdução às GPUs. Graphics Pipeline. Marcelo Walter UFPE. 3D Application or Game. 3D API: OpenGL or Direct 3D. Vertices Introdução às GPUs Marcelo Walter UFPE atualização/maio 2009 Graphics Pipeline 2 1 Graphics Pipeline glbegin(gl_triangles); gl3f(0.0,0.0,0.0); gl3f(1.0,0.0,0.0); gl3f(0.5,1.0,0.0);... glend(); 3 Graphics

More information

Topic 12: Database Programming using JDBC. Database & DBMS SQL JDBC

Topic 12: Database Programming using JDBC. Database & DBMS SQL JDBC Topic 12: Database Programming using JDBC Database & DBMS SQL JDBC Database A database is an integrated collection of logically related records or files consolidated into a common pool that provides data

More information

Respostas dos Exercícios de Programação Java

Respostas dos Exercícios de Programação Java Exercício 3. 3a) package exercicio.pkg3a; Respostas s Exercícios de Programação Java public class Exercicio3a int tab, i=1; System.out.print("Digite a tabuada: "); tab = leia.nextint(); System.out.println("\nTabuada

More information

Engineering Abstractions in Model Checking and Testing. Michael Achenbach Klaus Ostermann

Engineering Abstractions in Model Checking and Testing. Michael Achenbach Klaus Ostermann Engineering Abstractions in Model Checking and Testing Michael Achenbach Klaus Ostermann 1 This Talk What is abstraction engineering? How can we integrate abstractions with current tools? What more is

More information

CISC 323 (Week 9) Design of a Weather Program & Java File I/O

CISC 323 (Week 9) Design of a Weather Program & Java File I/O CISC 323 (Week 9) Design of a Weather Program & Java File I/O Jeremy Bradbury Teaching Assistant March 8 & 10, 2004 bradbury@cs.queensu.ca Programming Project The next three assignments form a programming

More information

COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA

COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA OUTLINE Postgresql installation Introduction of JDBC Stored Procedure POSTGRES INSTALLATION (1) Extract the source file Start the configuration

More information

Running SQL in Java and PHP

Running SQL in Java and PHP Running SQL in Java and PHP FCDB 9.6 9.7 Dr. Chris Mayfield Department of Computer Science James Madison University Mar 01, 2017 Introduction to JDBC JDBC = Java Database Connectivity 1. Connect to the

More information

sqoop Automatic database import Aaron Kimball Cloudera Inc. June 18, 2009

sqoop Automatic database import Aaron Kimball Cloudera Inc. June 18, 2009 sqoop Automatic database import Aaron Kimball Cloudera Inc. June 18, 2009 The problem Structured data already captured in databases should be used with unstructured data in Hadoop Tedious glue code necessary

More information

JDBC 3.0. Java Database Connectivity. 1 Java

JDBC 3.0. Java Database Connectivity. 1 Java JDBC 3.0 Database Connectivity 1 Contents 1 JDBC API 2 JDBC Architecture 3 Steps to code 4 Code 5 How to configure the DSN for ODBC Driver for MS-Access 6 Driver Types 7 JDBC-ODBC Bridge 8 Disadvantages

More information

Lecture 8. Database vs. Files SQL (I) Introduction to SQL database management systems (DBMS)

Lecture 8. Database vs. Files SQL (I) Introduction to SQL database management systems (DBMS) Lecture 8 SQL (I) Money are kept by boxes buried in the ground in the backyard. Money are kept in the bank 1 Source: system analysis and design methods, by Jeffrey L Whitten et al., 2 McGraw-Hill/Irwin,

More information

Communication.java 1

Communication.java 1 19.07.17 Communication.java 1 package framework.tracking; import java.io.ioexception; import java.net.datagrampacket; import java.net.inetaddress; import java.net.multicastsocket; import java.util.concurrent.concurrenthashmap;

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Java application using JDBC to connect to a database.

Java application using JDBC to connect to a database. JDBC(JAVA DATABASE CONNECTIVITY) The Java JDBC API enables Java applications to connect to relational databases via a standard API, so your Java applications become independent (almost) of the database

More information

Draft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior

Draft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior Chapter 6 Introduction to SQL 6.1 What is a SQL? When would I use it? SQL stands for Structured Query Language. It is a language used mainly for talking to database servers. It s main feature divisions

More information

Using a CVP VoiceXML application to implement a logical shadow queue for ICM

Using a CVP VoiceXML application to implement a logical shadow queue for ICM Using a CVP VoiceXML application to implement a logical shadow queue for ICM Introduction When calls are queuing in ICM, situations can arise in which greater visibility of the queue contents is required

More information

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws Lecture 14 Summary Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws 1 By the end of this lecture, you will be able to differentiate between errors, exceptions,

More information

CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7. Question 1. (2 points) What is the difference between a stream and a file?

CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7. Question 1. (2 points) What is the difference between a stream and a file? CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7 Question 1. (2 points) What is the difference between a stream and a file? A stream is an abstraction representing the flow of data from one place to

More information

NADABAS and its Environment

NADABAS and its Environment MZ:2011:02 NADABAS and its Environment Report from a remote mission to the National Statistical Institute of Mozambique, Maputo Mozambique 8 March - 1 April 2011 within the frame work of the AGREEMENT

More information