Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main.java;
- import java.io.*;
- import java.sql.*;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- public class DB2Test{
- public Connection getConnection() throws ClassNotFoundException, SQLException
- {
- Class. forName ( "COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver" );
- Connection connection =
- DriverManager.getConnection("jdbc:db2://dashdb-txn-sbox-yp-dal09-03.services.dal.bluemix.net:50001/BLUDB:sslConnection=true;","zdp02898","92f7w610c@39xrsv");
- System. out .println( "From DAO, connection obtained " );
- return connection;
- }
- public void insertData(Connection conn)
- {
- Statement stmt;
- try
- {
- stmt = conn.createStatement();
- stmt.executeUpdate("insert into events (shortname, location, begindate, enddate, contact) values('shortname1', 'location1','begindat1e','e1nddate','con1tact')");
- stmt.close();
- conn.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public Map<String,String> pullData(Connection conn, String identifier)
- {
- ResultSet rs;
- Statement stmt;
- String pullquery = "Select * from sponsorshipTable where EID=" + identifier;
- Map<String, String> data = new HashMap<String, String>();
- try
- {
- BufferedReader textreader = new BufferedReader(new FileReader("DB2Map.txt"));
- int MapLines = countLines("DB2Map.txt");
- stmt = conn.createStatement();
- System.out.println("heh");
- System.out.println(stmt);
- System.out.println(conn);
- rs = stmt.executeQuery(pullquery);
- System.out.println("here");
- rs.next();
- System.out.println(rs.getString(2));
- int counter = 1;
- while (counter < MapLines + 1){
- String line = textreader.readLine();
- String temp = rs.getString(counter);
- System.out.println(temp);
- if ((temp == null) || temp.equals("null")){
- data.put(line, "");
- }
- else{
- data.put(line, rs.getString(counter));
- }
- counter++;
- }
- rs.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return data;
- }
- public void createMap(ArrayList data){
- }
- public static int countLines(String filename) throws IOException {
- InputStream is = new BufferedInputStream(new FileInputStream(filename));
- try {
- byte[] c = new byte[1024];
- int count = 0;
- int readChars = 0;
- boolean empty = true;
- while ((readChars = is.read(c)) != -1) {
- empty = false;
- for (int i = 0; i < readChars; ++i) {
- if (c[i] == '\n') {
- ++count;
- }
- }
- }
- return (count == 0 && !empty) ? 1 : count;
- } finally {
- is.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement