1 27 28 32 package xeus.bottomline; 33 34 import java.sql.Connection ; 35 import java.sql.DriverManager ; 36 import java.sql.ResultSet ; 37 import java.sql.SQLException ; 38 import java.sql.Statement ; 39 import java.util.Properties ; 40 41 45 public class Bottomline { 46 47 private Properties props; 48 49 60 public Bottomline(String jar, String className, String url, String user, 61 String password) throws ClassNotFoundException , 62 InstantiationException , IllegalAccessException , SQLException { 63 props = new Properties (); 64 props.put(BottomlineConstants.USER, user); 65 props.put(BottomlineConstants.PASSWORD, password); 66 props.put(BottomlineConstants.DRIVER_JAR, jar); 67 props.put(BottomlineConstants.DRIVER_CLASS, className); 68 props.put("url", url); 69 } 70 71 74 public Bottomline(Properties props) { 75 this.props = props; 76 } 77 78 85 public Connection getConnection() throws SQLException , 86 InstantiationException , IllegalAccessException , 87 ClassNotFoundException { 88 Class.forName("xeus.bottomline.BottomlineDriver"); 89 return DriverManager.getConnection(props 90 .getProperty(BottomlineConstants.CONNECTION_URL), props); 91 } 92 93 96 public static void main(String [] args) throws Exception { 97 Class.forName("xeus.bottomline.BottomlineDriver", true, Thread 98 .currentThread().getContextClassLoader()); 99 Properties props = new Properties (); 100 props.put("user", "root"); 101 props.put("password", "root"); 102 props 103 .put( 104 "jar", 105 "D:\\software\\stuff 4\\mysql-connector-java-5.0.3\\" 106 + "mysql-connector-java-5.0.3\\mysql-connector-java-5.0.3-bin.jar"); 107 props.put("class", "com.mysql.jdbc.Driver"); 108 109 String jar = "D:\\software\\stuff 4\\mysql-connector-java-5.0.3\\" 110 + "mysql-connector-java-5.0.3\\mysql-connector-java-5.0.3-bin.jar"; 111 112 115 Connection conn = DriverManager 116 .getConnection("jdbc:bottomline:mysql://localhost:3306/timesheet?user=root&password=root&jar=" 117 + jar + "&class=com.mysql.jdbc.Driver"); 118 119 123 Statement s = conn.createStatement(); 124 ResultSet rs = s.executeQuery("SELECT * FROM pts_worker"); 125 126 while (rs.next()) 127 System.out.println(rs.getString("wname")); 128 129 rs.close(); 130 s.close(); 131 133 Properties props1 = new Properties (); 134 props1.put("user", "root"); 135 props1.put("password", "root"); 136 props1.put("class", "com.mysql.jdbc.Driver"); 137 props1.put("jar", 138 "D:\\software\\mysql-connector-java-2.0.14\\mysql-connector-java-2.0.14\\" 139 + "mysql-connector-java-2.0.14-bin.jar"); 140 141 try { 142 Connection conn1 = DriverManager.getConnection( 143 "jdbc:bottomline:mysql://localhost:3306/timesheet", props1); 144 145 Statement s1 = conn1.createStatement(); 146 ResultSet rs1 = s1.executeQuery("SELECT * FROM pts_worker"); 147 148 while (rs1.next()) 149 System.out.println(rs1.getString("wname")); 150 151 rs1.close(); 152 s1.close(); 153 conn1.close(); 154 } catch (Exception e) { 155 e.printStackTrace(System.err); 156 } 157 158 161 s = conn.createStatement(); 162 rs = s.executeQuery("SELECT * FROM pts_worker"); 163 164 while (rs.next()) 165 System.out.println(rs.getString("wname")); 166 167 rs.close(); 168 s.close(); 169 conn.close(); 170 } 171 } 172 | Popular Tags |