List of usage examples for java.sql DriverManager getConnection
private static Connection getConnection(String url, java.util.Properties info, Class<?> caller) throws SQLException
From source file:ex4.java
public static void main(String[] params) { CommandLine commandLine = null;/*from www. j ava 2 s . c om*/ String sqlpath = "", host = "", port = "3306", username = "", password = "", database = ""; Boolean query = false; Option option_sql = Option.builder("s").argName("sql").hasArg() .desc("Path to a file containing a valid MySQL sql statement").build(); Option option_hostname = Option.builder("h").argName("host").hasArg().desc("ClearDB MySQL Hostname") .build(); Option option_port = Option.builder("n").argName("port").hasArg().desc("ClearDB MySQL Port").build(); Option option_username = Option.builder("u").argName("username").hasArg().desc("ClearDB MySQL Username") .build(); Option option_password = Option.builder("p").argName("password").hasArg().desc("ClearDB MySQL Password") .build(); Option option_dbname = Option.builder("d").argName("dbname").hasArg().desc("ClearDB MySQL Database Name") .build(); Option option_help = Option.builder("w").argName("wanthelp").hasArg().desc("Help").build(); Option option_query = Option.builder().longOpt("query").desc("Query type SQL Statement").build(); Options options = new Options(); CommandLineParser parser = new DefaultParser(); options.addOption(option_sql); options.addOption(option_hostname); options.addOption(option_port); options.addOption(option_username); options.addOption(option_password); options.addOption(option_dbname); options.addOption(option_query); options.addOption(option_help); try { commandLine = parser.parse(options, params); } catch (MissingOptionException e) { help(options); } catch (MissingArgumentException e) { help(options); } catch (ParseException e) { System.out.println(e); } if (commandLine.hasOption("w") || params.length == 0) { help(options); } if (commandLine.hasOption("s")) { sqlpath = commandLine.getOptionValue("s"); } else { System.out.println("Missing path to a SQL statement file"); help(options); } if (commandLine.hasOption("h")) { host = commandLine.getOptionValue("h"); } else { System.out.println("Missing ClearDB hostname (e.g. us-cdbr-iron-east-??.cleardb.net)"); help(options); } if (commandLine.hasOption("n")) { port = commandLine.getOptionValue("n"); } else { System.out.println("Missing ClearDB Port Value. Defaulting to 3306"); } if (commandLine.hasOption("u")) { username = commandLine.getOptionValue("u"); } else { System.out.println("Missing ClearDB Username"); help(options); } if (commandLine.hasOption("p")) { password = commandLine.getOptionValue("p"); } else { System.out.println("Missing ClearDB Password"); help(options); } if (commandLine.hasOption("d")) { database = commandLine.getOptionValue("d"); } else { System.out.println("Missing ClearDB Database Name"); help(options); } if (commandLine.hasOption("query")) { query = true; } String connectionURL = new StringBuilder().append("jdbc:mysql://").append(host).append(":").append(port) .append("/").append(database).append("?reconnect=true").toString(); try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println(e); } try { Connection con = DriverManager.getConnection(connectionURL, username, password); Statement stmt = con.createStatement(); if (query) { System.out.println("Querying target MySQL DB ..."); ResultSet rs = stmt.executeQuery(readFile(sqlpath, Charset.defaultCharset())); while (rs.next()) System.out.println(rs.getInt("emp_no") + " " + rs.getDate("birth_date") + " " + rs.getString("first_name") + " " + rs.getString("last_name") + " " + rs.getString("gender") + " " + rs.getDate("hire_date")); } else { System.out.println("Updating target MySQL DB ..."); int result = stmt.executeUpdate(readFile(sqlpath, Charset.defaultCharset())); System.out.println(result); } con.close(); } catch (Exception e) { System.out.println(e); } }
From source file:com.mycompany.mavenproject4.web.java
/** * @param args the command line arguments *//*w w w. j a va2 s .c om*/ public static void main(String[] args) { System.out.println("Enter your choice do you want to work with \n 1.PostGreSQL \n 2.Redis \n 3.Mongodb"); InputStreamReader IORdatabase = new InputStreamReader(System.in); BufferedReader BIOdatabase = new BufferedReader(IORdatabase); String Str1 = null; try { Str1 = BIOdatabase.readLine(); } catch (Exception E7) { System.out.println(E7.getMessage()); } // loading data from the CSV file CsvReader data = null; try { data = new CsvReader("\\data\\Consumer_Complaints.csv"); } catch (FileNotFoundException EB) { System.out.println(EB.getMessage()); } int noofcolumn = 5; int noofrows = 100; int loops = 0; try { data = new CsvReader("\\data\\Consumer_Complaints.csv"); } catch (FileNotFoundException E) { System.out.println(E.getMessage()); } String[][] Dataarray = new String[noofrows][noofcolumn]; try { while (data.readRecord()) { String v; String[] x; v = data.getRawRecord(); x = v.split(","); for (int j = 0; j < noofcolumn; j++) { String value = null; int z = j; value = x[z]; try { Dataarray[loops][j] = value; } catch (Exception E) { System.out.println(E.getMessage()); } // System.out.println(Dataarray[iloop][j]); } loops = loops + 1; } } catch (IOException Em) { System.out.println(Em.getMessage()); } data.close(); // connection to Database switch (Str1) { // postgre code goes here case "1": Connection Conn = null; Statement Stmt = null; URI dbUri = null; String choice = null; InputStreamReader objin = new InputStreamReader(System.in); BufferedReader objbuf = new BufferedReader(objin); try { Class.forName("org.postgresql.Driver"); } catch (Exception E1) { System.out.println(E1.getMessage()); } String username = "ahkyjdavhedkzg"; String password = "2f7c3_MBJbIy1uJsFyn7zebkhY"; String dbUrl = "jdbc:postgresql://ec2-54-83-199-54.compute-1.amazonaws.com:5432/d2l6hq915lp9vi?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"; // now update data in the postgress Database /* for(int i=0;i<RowCount;i++) { try { Conn= DriverManager.getConnection(dbUrl, username, password); Stmt = Conn.createStatement(); String Connection_String = "insert into Webdata (Id,Product,state,Submitted,Complaintid) values (' "+ Dataarray[i][0]+" ',' "+ Dataarray[i][1]+" ',' "+ Dataarray[i][2]+" ',' "+ Dataarray[i][3]+" ',' "+ Dataarray[i][4]+" ')"; Stmt.executeUpdate(Connection_String); Conn.close(); } catch(SQLException E4) { System.out.println(E4.getMessage()); } } */ // Quering with the Database System.out.println("1. Display Data "); System.out.println("2. Select data based on primary key"); System.out.println("3. Select data based on Other attributes e.g Name"); System.out.println("Enter your Choice "); try { choice = objbuf.readLine(); } catch (IOException E) { System.out.println(E.getMessage()); } switch (choice) { case "1": try { Conn = DriverManager.getConnection(dbUrl, username, password); Stmt = Conn.createStatement(); String Connection_String = " Select * from Webdata;"; ResultSet objRS = Stmt.executeQuery(Connection_String); while (objRS.next()) { System.out.println(" ID: " + objRS.getInt("ID")); System.out.println("Product Name: " + objRS.getString("Product")); System.out.println("Which state: " + objRS.getString("State")); System.out.println("Sumbitted through: " + objRS.getString("Submitted")); System.out.println("Complain Number: " + objRS.getString("Complaintid")); Conn.close(); } } catch (Exception E2) { System.out.println(E2.getMessage()); } break; case "2": System.out.println("Enter Id(Primary Key) :"); InputStreamReader objkey = new InputStreamReader(System.in); BufferedReader objbufkey = new BufferedReader(objkey); int key = 0; try { key = Integer.parseInt(objbufkey.readLine()); } catch (IOException E) { System.out.println(E.getMessage()); } try { Conn = DriverManager.getConnection(dbUrl, username, password); Stmt = Conn.createStatement(); String Connection_String = " Select * from Webdata where Id=" + key + ";"; ResultSet objRS = Stmt.executeQuery(Connection_String); while (objRS.next()) { //System.out.println(" ID: " + objRS.getInt("ID")); System.out.println("Product Name: " + objRS.getString("Product")); System.out.println("Which state: " + objRS.getString("State")); System.out.println("Sumbitted through: " + objRS.getString("Submitted")); System.out.println("Complain Number: " + objRS.getString("Complaintid")); Conn.close(); } } catch (Exception E2) { System.out.println(E2.getMessage()); } break; case "3": //String Name=null; System.out.println("Enter Complaintid to find the record"); // Scanner input = new Scanner(System.in); // int Number = 0; try { InputStreamReader objname = new InputStreamReader(System.in); BufferedReader objbufname = new BufferedReader(objname); Number = Integer.parseInt(objbufname.readLine()); } catch (Exception E10) { System.out.println(E10.getMessage()); } //System.out.println(Name); try { Conn = DriverManager.getConnection(dbUrl, username, password); Stmt = Conn.createStatement(); String Connection_String = " Select * from Webdata where complaintid=" + Number + ";"; //2 System.out.println(Connection_String); ResultSet objRS = Stmt.executeQuery(Connection_String); while (objRS.next()) { int id = objRS.getInt("id"); System.out.println(" ID: " + id); System.out.println("Product Name: " + objRS.getString("Product")); String state = objRS.getString("state"); System.out.println("Which state: " + state); String Submitted = objRS.getString("submitted"); System.out.println("Sumbitted through: " + Submitted); String Complaintid = objRS.getString("complaintid"); System.out.println("Complain Number: " + Complaintid); } Conn.close(); } catch (Exception E2) { System.out.println(E2.getMessage()); } break; } try { Conn.close(); } catch (SQLException E6) { System.out.println(E6.getMessage()); } break; // Redis code goes here case "2": int Length = 0; String ID = null; Length = 100; // Connection to Redis Jedis jedis = new Jedis("pub-redis-13274.us-east-1-2.1.ec2.garantiadata.com", 13274); jedis.auth("rfJ8OLjlv9NjRfry"); System.out.println("Connected to Redis Database"); // Storing values in the database /* for(int i=0;i<Length;i++) { //Store data in redis int j=i+1; jedis.hset("Record:" + j , "Product", Dataarray[i][1]); jedis.hset("Record:" + j , "State ", Dataarray[i][2]); jedis.hset("Record:" + j , "Submitted", Dataarray[i][3]); jedis.hset("Record:" + j , "Complaintid", Dataarray[i][4]); } */ System.out.println( "Search by \n 11.Get records through primary key \n 22.Get Records through Complaintid \n 33.Display "); InputStreamReader objkey = new InputStreamReader(System.in); BufferedReader objbufkey = new BufferedReader(objkey); String str2 = null; try { str2 = objbufkey.readLine(); } catch (IOException E) { System.out.println(E.getMessage()); } switch (str2) { case "11": System.out.print("Enter Primary Key : "); InputStreamReader IORKey = new InputStreamReader(System.in); BufferedReader BIORKey = new BufferedReader(IORKey); String ID1 = null; try { ID1 = BIORKey.readLine(); } catch (IOException E3) { System.out.println(E3.getMessage()); } Map<String, String> properties = jedis.hgetAll("Record:" + Integer.parseInt(ID1)); for (Map.Entry<String, String> entry : properties.entrySet()) { System.out.println("Product:" + jedis.hget("Record:" + Integer.parseInt(ID1), "Product")); System.out.println("State:" + jedis.hget("Record:" + Integer.parseInt(ID1), "State")); System.out.println("Submitted:" + jedis.hget("Record:" + Integer.parseInt(ID1), "Submitted")); System.out .println("Complaintid:" + jedis.hget("Record:" + Integer.parseInt(ID1), "Complaintid")); } break; case "22": System.out.print(" Enter Complaintid : "); InputStreamReader IORName1 = new InputStreamReader(System.in); BufferedReader BIORName1 = new BufferedReader(IORName1); String ID2 = null; try { ID2 = BIORName1.readLine(); } catch (IOException E3) { System.out.println(E3.getMessage()); } for (int i = 0; i < 100; i++) { Map<String, String> properties3 = jedis.hgetAll("Record:" + i); for (Map.Entry<String, String> entry : properties3.entrySet()) { String value = entry.getValue(); if (entry.getValue().equals(ID2)) { System.out .println("Product:" + jedis.hget("Record:" + Integer.parseInt(ID2), "Product")); System.out.println("State:" + jedis.hget("Record:" + Integer.parseInt(ID2), "State")); System.out.println( "Submitted:" + jedis.hget("Record:" + Integer.parseInt(ID2), "Submitted")); System.out.println( "Complaintid:" + jedis.hget("Record:" + Integer.parseInt(ID2), "Complaintid")); } } } break; case "33": for (int i = 1; i < 21; i++) { Map<String, String> properties3 = jedis.hgetAll("Record:" + i); for (Map.Entry<String, String> entry : properties3.entrySet()) { System.out.println("Product:" + jedis.hget("Record:" + i, "Product")); System.out.println("State:" + jedis.hget("Record:" + i, "State")); System.out.println("Submitted:" + jedis.hget("Record:" + i, "Submitted")); System.out.println("Complaintid:" + jedis.hget("Record:" + i, "Complaintid")); } } break; } break; // mongo db case "3": MongoClient mongo = new MongoClient(new MongoClientURI( "mongodb://naikhpratik:naikhpratik@ds053964.mongolab.com:53964/heroku_6t7n587f")); DB db; db = mongo.getDB("heroku_6t7n587f"); // storing values in the database /*for(int i=0;i<100;i++) { BasicDBObject document = new BasicDBObject(); document.put("Id", i+1); document.put("Product", Dataarray[i][1]); document.put("State", Dataarray[i][2]); document.put("Submitted", Dataarray[i][3]); document.put("Complaintid", Dataarray[i][4]); db.getCollection("Naiknaik").insert(document); }*/ System.out.println("Search by \n 1.Enter Primary key \n 2.Enter Complaintid \n 3.Display"); InputStreamReader objkey6 = new InputStreamReader(System.in); BufferedReader objbufkey6 = new BufferedReader(objkey6); String str3 = null; try { str3 = objbufkey6.readLine(); } catch (IOException E) { System.out.println(E.getMessage()); } switch (str3) { case "1": System.out.println("Enter the Primary Key"); InputStreamReader IORPkey = new InputStreamReader(System.in); BufferedReader BIORPkey = new BufferedReader(IORPkey); int Pkey = 0; try { Pkey = Integer.parseInt(BIORPkey.readLine()); } catch (IOException E) { System.out.println(E.getMessage()); } BasicDBObject inQuery = new BasicDBObject(); inQuery.put("Id", Pkey); DBCursor cursor = db.getCollection("Naiknaik").find(inQuery); while (cursor.hasNext()) { // System.out.println(cursor.next()); System.out.println(cursor.next()); } break; case "2": System.out.println("Enter the Product to Search"); InputStreamReader objName = new InputStreamReader(System.in); BufferedReader objbufName = new BufferedReader(objName); String Name = null; try { Name = objbufName.readLine(); } catch (IOException E) { System.out.println(E.getMessage()); } BasicDBObject inQuery1 = new BasicDBObject(); inQuery1.put("Product", Name); DBCursor cursor1 = db.getCollection("Naiknaik").find(inQuery1); while (cursor1.hasNext()) { // System.out.println(cursor.next()); System.out.println(cursor1.next()); } break; case "3": for (int i = 1; i < 21; i++) { BasicDBObject inQuerya = new BasicDBObject(); inQuerya.put("_id", i); DBCursor cursora = db.getCollection("Naiknaik").find(inQuerya); while (cursora.hasNext()) { // System.out.println(cursor.next()); System.out.println(cursora.next()); } } break; } break; } }
From source file:com.ibm.research.rdf.store.runtime.service.sql.UpdateHelper.java
public static void main(String[] args) { String JDBC_URL = "jdbc:db2://localhost:10997/lubm"; String user = "db2inst1"; String password = "db2admin"; String backend = "db2"; String schema = "db2inst1"; String store = "lubm_100m_r"; int lock = 1; int dph_size = 11; int rph_size = 4; String[][] triples = { { "http://usersub1/", "http://testpred1/", "http://userobj1/" }, { "http://usersub1/", "http://testpred2/", "http://userobj2/" }, { "http://usersub1/", "http://testpred1/", "userobj3" }, { "http://usersub2/", "http://testpred2/", "http://userobj2/" }, { "http://usersub1/", "http://testpred3/", "userobj4" }, { "http://usersub1/", "http://testpred4/", "userobj4" }, { "http://usersub2/", "http://testpred8/", "http://userobj2/" }, { "http://usersub2/", "http://testpred6/", "http://userobj2/" }, { "http://usersub2/", "http://testpred7/", "http://userobj2/" }, { "http://usersub1/", "http://testpred5/", "userobj5" }, { "http://usersub2/", "http://testpred9/", "http://userobj2/" }, { "http://usersub3/", "http://testpred2/", "http://userobj2/" }, { "http://usersub1/", "http://testpred1/", "userobj4" }, { "http://usersub1/", "http://testpred1/", "userobj5" }, { "http://usersub1/", "http://testpred3/", "userobj5" }, { "http://usersub4/", "http://testpred2/", "http://userobj2/" }, { "http://usersub3/", "http://testpred1/", "userobj3" } }; try {//from w w w . j a v a2s .c o m String classNameString = new String("com.ibm.db2.jcc.DB2Driver"); Class.forName(classNameString); Connection conn = DriverManager.getConnection(JDBC_URL, user, password); String gid = "DEF"; //add triples to graph DEF for (int i = 0; i < triples.length; i++) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int obj_dt = obj.startsWith("http://") ? 10002 : 5001; int dft_col = i % 2; addTriple(conn, backend, schema, store, sub, pred, obj, obj_dt, dft_col, dft_col, gid, lock); } gid = "G1"; //add triples to graph G1 //some operations will fail due to UNIQUE indexes (on DS, RS) without GID for (int i = 0; i < triples.length; i++) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int obj_dt = obj.startsWith("http://") ? 10002 : 5001; int dft_col = i % 2; addTriple(conn, backend, schema, store, sub, pred, obj, obj_dt, dft_col, dft_col, gid, lock); } gid = "DEF"; //delete triples to graph DEF for (int i = triples.length - 1; i >= 0; i--) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int dft_col = i % 2; deleteTriple(conn, backend, schema, store, sub, pred, obj, dph_size, rph_size, dft_col, dft_col, gid, lock); } gid = "G1"; //delete triples to graph G1 for (int i = triples.length - 1; i >= 0; i--) { String sub = triples[i][0]; String pred = triples[i][1]; String obj = triples[i][2]; int dft_col = i % 2; deleteTriple(conn, backend, schema, store, sub, pred, obj, dph_size, rph_size, dft_col, dft_col, gid, lock); } } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:GIST.IzbirkomExtractor.IzbirkomExtractor.java
/** * @param args// ww w.ja v a 2 s.c om */ public static void main(String[] args) { // process command-line options Options options = new Options(); options.addOption("n", "noaddr", false, "do not do any address matching (for testing)"); options.addOption("i", "info", false, "create and populate address information table"); options.addOption("h", "help", false, "this message"); // database connection options.addOption("s", "server", true, "database server to connect to"); options.addOption("d", "database", true, "OSM database name"); options.addOption("u", "user", true, "OSM database user name"); options.addOption("p", "pass", true, "OSM database password"); // logging options options.addOption("l", "logdir", true, "log file directory (default './logs')"); options.addOption("e", "loglevel", true, "log level (default 'FINEST')"); // automatically generate the help statement HelpFormatter help_formatter = new HelpFormatter(); // database URI for connection String dburi = null; // Information message for help screen String info_msg = "IzbirkomExtractor [options] <html_directory>"; try { CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h') || cmd.getArgs().length != 1) { help_formatter.printHelp(info_msg, options); System.exit(1); } /* prohibit n and i together */ if (cmd.hasOption('n') && cmd.hasOption('i')) { System.err.println("Options 'n' and 'i' cannot be used together."); System.exit(1); } /* require database arguments without -n */ if (cmd.hasOption('n') && (cmd.hasOption('s') || cmd.hasOption('d') || cmd.hasOption('u') || cmd.hasOption('p'))) { System.err.println("Options 'n' and does not need any databse parameters."); System.exit(1); } /* require all 4 database options to be used together */ if (!cmd.hasOption('n') && !(cmd.hasOption('s') && cmd.hasOption('d') && cmd.hasOption('u') && cmd.hasOption('p'))) { System.err.println( "For database access all of the following arguments have to be specified: server, database, user, pass"); System.exit(1); } /* useful variables */ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm"); String dateString = formatter.format(new Date()); /* setup logging */ File logdir = new File(cmd.hasOption('l') ? cmd.getOptionValue('l') : "logs"); FileUtils.forceMkdir(logdir); File log_file_name = new File( logdir + "/" + IzbirkomExtractor.class.getName() + "-" + formatter.format(new Date()) + ".log"); FileHandler log_file = new FileHandler(log_file_name.getPath()); /* create "latest" link to currently created log file */ Path latest_log_link = Paths.get(logdir + "/latest"); Files.deleteIfExists(latest_log_link); Files.createSymbolicLink(latest_log_link, Paths.get(log_file_name.getName())); log_file.setFormatter(new SimpleFormatter()); LogManager.getLogManager().reset(); // prevents logging to console logger.addHandler(log_file); logger.setLevel(cmd.hasOption('e') ? Level.parse(cmd.getOptionValue('e')) : Level.FINEST); // open directory with HTML files and create file list File dir = new File(cmd.getArgs()[0]); if (!dir.isDirectory()) { System.err.println("Unable to find directory '" + cmd.getArgs()[0] + "', exiting"); System.exit(1); } PathMatcher pmatcher = FileSystems.getDefault() .getPathMatcher("glob:? * ?*.html"); ArrayList<File> html_files = new ArrayList<>(); for (Path file : Files.newDirectoryStream(dir.toPath())) if (pmatcher.matches(file.getFileName())) html_files.add(file.toFile()); if (html_files.size() == 0) { System.err.println("No matching HTML files found in '" + dir.getAbsolutePath() + "', exiting"); System.exit(1); } // create csvResultSink FileOutputStream csvout_file = new FileOutputStream("parsed_addresses-" + dateString + ".csv"); OutputStreamWriter csvout = new OutputStreamWriter(csvout_file, "UTF-8"); ResultSink csvResultSink = new CSVResultSink(csvout, new CSVStrategy('|', '"', '#')); // Connect to DB and osmAddressMatcher AddressMatcher osmAddressMatcher; DBSink dbSink = null; DBInfoSink dbInfoSink = null; if (cmd.hasOption('n')) { osmAddressMatcher = new DummyAddressMatcher(); } else { dburi = "jdbc:postgresql://" + cmd.getOptionValue('s') + "/" + cmd.getOptionValue('d'); Connection con = DriverManager.getConnection(dburi, cmd.getOptionValue('u'), cmd.getOptionValue('p')); osmAddressMatcher = new OsmAddressMatcher(con); dbSink = new DBSink(con); if (cmd.hasOption('i')) dbInfoSink = new DBInfoSink(con); } /* create resultsinks */ SinkMultiplexor sm = SinkMultiplexor.newSinkMultiplexor(); sm.addResultSink(csvResultSink); if (dbSink != null) { sm.addResultSink(dbSink); if (dbInfoSink != null) sm.addResultSink(dbInfoSink); } // create tableExtractor TableExtractor te = new TableExtractor(osmAddressMatcher, sm); // TODO: printout summary of options: processing date/time, host, directory of HTML files, jdbc uri, command line with parameters // iterate through files logger.info("Start processing " + html_files.size() + " files in " + dir); for (int i = 0; i < html_files.size(); i++) { System.err.println("Parsing #" + i + ": " + html_files.get(i)); te.processHTMLfile(html_files.get(i)); } System.err.println("Processed " + html_files.size() + " HTML files"); logger.info("Finished processing " + html_files.size() + " files in " + dir); } catch (ParseException e1) { System.err.println("Failed to parse CLI: " + e1.getMessage()); help_formatter.printHelp(info_msg, options); System.exit(1); } catch (IOException e) { System.err.println("I/O Exception: " + e.getMessage()); e.printStackTrace(); System.exit(1); } catch (SQLException e) { System.err.println("Database '" + dburi + "': " + e.getMessage()); System.exit(1); } catch (ResultSinkException e) { System.err.println("Failed to initialize ResultSink: " + e.getMessage()); System.exit(1); } catch (TableExtractorException e) { System.err.println("Failed to initialize Table Extractor: " + e.getMessage()); System.exit(1); } catch (CloneNotSupportedException | IllegalAccessException | InstantiationException e) { System.err.println("Something really odd happened: " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:InsertDateToOracle.java
public static Connection getConnection() throws Exception { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:databaseName"; Class.forName(driver);/*from w w w. j a v a 2 s .co m*/ return DriverManager.getConnection(url, "userName", "password"); }
From source file:Main.java
public static Connection getConnection() throws Exception { String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String url = "jdbc:odbc:excelDB"; String username = "yourName"; String password = "yourPass"; Class.forName(driver);//www .j ava2 s . c o m return DriverManager.getConnection(url, username, password); }
From source file:Main.java
public static Connection getConnection() throws Exception { String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/databaseName"; String username = "username"; String password = "password"; Class.forName(driver);/*from www .ja v a2 s. c o m*/ Connection conn = DriverManager.getConnection(url, username, password); return conn; }
From source file:GetDateFromOracle.java
public static Connection getConnection() throws Exception { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:databaseName"; Class.forName(driver);//w w w . j a va2 s. c o m return DriverManager.getConnection(url, "name", "password"); }
From source file:MainClass.java
public static Connection getConnection() throws Exception { String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String url = "jdbc:odbc:northwind"; String username = ""; String password = ""; Class.forName(driver); // load JDBC-ODBC driver return DriverManager.getConnection(url, username, password); }
From source file:DemoPreparedStatementSetIntegers.java
public static Connection getConnection() throws Exception { String driver = "org.gjt.mm.mysql.Driver"; String url = "jdbc:mysql://localhost/databaseName"; String username = "root"; String password = "root"; Class.forName(driver);//from w w w . ja v a 2 s.c o m Connection conn = DriverManager.getConnection(url, username, password); return conn; }