| Home >> All >> org >> alicebot >> server >> sql >> [ pool Javadoc ] |
Source code: org/alicebot/server/sql/pool/DbAccess.java
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov. 2 // Jad home page: http://www.geocities.com/kpdus/jad.html 3 // Decompiler options: packimports(3) 4 5 package org.alicebot.server.sql.pool; 6 7 import java.sql.*; 8 import org.alicebot.server.core.logging.Log; 9 import org.alicebot.server.core.util.DeveloperError; 10 import org.alicebot.server.core.util.UserError; 11 12 public class DbAccess 13 { 14 15 public DbAccess(String s, String s1, String s2, String s3) 16 { 17 driver = s; 18 url = s1; 19 user = s2; 20 password = s3; 21 connect(); 22 } 23 24 public DbAccess(Connection connection1) 25 { 26 connection = connection1; 27 } 28 29 public void connect() 30 { 31 if(connection == null) 32 { 33 try 34 { 35 Class.forName(driver); 36 } 37 catch(ClassNotFoundException classnotfoundexception) 38 { 39 throw new UserError("Could not find your database driver."); 40 } 41 try 42 { 43 if(user == null || password == null) 44 connection = DriverManager.getConnection(url); 45 else 46 connection = DriverManager.getConnection(url, user, password); 47 } 48 catch(SQLException sqlexception) 49 { 50 throw new UserError("Could not connect to \"" + url + "\". Please check that the parameters specified in your server properties file are correct.", sqlexception); 51 } 52 try 53 { 54 statement = connection.createStatement(); 55 } 56 catch(SQLException sqlexception1) 57 { 58 throw new UserError("Could not create a SQL statement using your database."); 59 } 60 } 61 } 62 63 public ResultSet executeQuery(String s) 64 throws SQLException 65 { 66 if(statement == null) 67 throw new DeveloperError("Tried to execute query before creating Statement object!"); 68 try 69 { 70 return statement.executeQuery(s); 71 } 72 catch(SQLException sqlexception) 73 { 74 Log.userinfo("Problem executing a query on your database. Check structure and availability.", new String[] { 75 Log.ERROR, Log.DATABASE 76 }); 77 throw sqlexception; 78 } 79 } 80 81 public int executeUpdate(String s) 82 { 83 if(statement == null) 84 throw new DeveloperError("Tried to execute query before creating Statement object!"); 85 try 86 { 87 return statement.executeUpdate(s); 88 } 89 catch(SQLException sqlexception) 90 { 91 throw new UserError("Problem executing an update on your database. Check structure and availability.", sqlexception); 92 } 93 } 94 95 public Connection getConnection() 96 { 97 return connection; 98 } 99 100 public String getDriver() 101 { 102 return driver; 103 } 104 105 public String getPassword() 106 { 107 return password; 108 } 109 110 public Statement getStatement() 111 { 112 return statement; 113 } 114 115 public String getUrl() 116 { 117 return url; 118 } 119 120 public String getUser() 121 { 122 return user; 123 } 124 125 public void setConnection(Connection connection1) 126 { 127 connection = connection1; 128 } 129 130 public void setDriver(String s) 131 { 132 driver = s; 133 } 134 135 public void setPassword(String s) 136 { 137 password = s; 138 } 139 140 public void setUrl(String s) 141 { 142 url = s; 143 } 144 145 public void setUser(String s) 146 { 147 user = s; 148 } 149 150 protected Connection connection; 151 protected Statement statement; 152 protected String driver; 153 protected String url; 154 protected String user; 155 protected String password; 156 }