9 import java
.lang
.Class
;
10 //import java.sql.SQLException;
12 public class JdbcSqlDataSource
implements javax
.sql
.DataSource
, javax
.naming
.Referenceable
, java
.io
.Serializable
18 DriverManager
.registerDriver(new JdbcSqlDriver());
22 System
.out
.println ("CSql JDBC Driver: " + e
);
26 private String databaseName
="csql";
27 private String dataSourceName
;
28 private String serverName
="localhost";
29 private String password
="manager";
30 private String userName
="root";
31 private String mode
="";
32 transient JdbcSqlDriver driver
;
33 transient private PrintWriter printer
;
34 private int loginTimeout
;
35 private String jdbcurl
="jdbc:";
36 private int portno
= 5678;
37 boolean explicityUrlUsed
=false;
38 private String explicityUrl
="";
39 public JdbcSqlDataSource()
46 public Connection
getConnection() throws SQLException
48 return this.getConnection(getUserName(),getPassword());
50 public synchronized Connection
getConnection(String username
, String password
) throws SQLException
53 if(!explicityUrlUsed
){
54 url
= jdbcurl
+ mode
+"://" + serverName
+ ":" + portno
+"/" + databaseName
;
58 Properties info
= new Properties();
60 info
.put("user", username
);
62 info
.put("password", password
);
63 Connection conn
= findDriver().connect(url
, info
);
69 public void setUrl(String url
)
71 if(explicityUrlUsed
) {
75 public String
getUrl()
78 if(!explicityUrlUsed
){
79 url
= jdbcurl
+ mode
+"://" + serverName
+ ":" + portno
+"/" + databaseName
;
86 public void setPort(int port
)
95 public void setMode(String mode
)
99 public String
getMode()
104 JdbcSqlDriver
findDriver() throws SQLException
106 String url
= getUrl();
107 if (driver
== null || !driver
.acceptsURL(url
))
109 //new JdbcSqlDriver();
110 driver
=(JdbcSqlDriver
) DriverManager
.getDriver(url
);
114 public java
.io
.PrintWriter
getLogWriter() throws SQLException
119 public void setLogWriter(java
.io
.PrintWriter out
)
124 public void setLoginTimeout(int seconds
)throws SQLException
126 loginTimeout
= seconds
;
130 public int getLoginTimeout()
135 public Reference
getReference() throws NamingException
137 Reference ref
= new Reference(this.getClass().getName(),"csql.jdbc.JdbcSqlObjectFactory", null);
138 ref
.add( new StringRefAddr("serverName", getServerName()) );
139 ref
.add( new StringRefAddr("databaseName",getDatabaseName()));
140 ref
.add( new StringRefAddr("mode",getMode()));
141 ref
.add( new StringRefAddr("port",""+getPort()));
142 ref
.add( new StringRefAddr("user",getUserName()));
143 ref
.add( new StringRefAddr("password",getPassword()));
144 ref
.add( new StringRefAddr("url",getUrl()));
149 public String
getServerName(){
153 public void setServerName(String serverName
){
154 this.serverName
=serverName
;
157 public String
getDatabaseName(){
161 public void setDatabaseName(String databaseName
){
162 this.databaseName
=databaseName
;
165 public String
getUserName()
170 public void setUserName(String un
)
175 public String
getPassword()
180 public void setPassword(String pw
)
185 public boolean isWrapperFor(Class ifact
) throws SQLException
188 return ifact
.isInstance(this);
191 public <T
> T
unwrap(java
.lang
.Class
<T
> iface
) throws SQLException
193 return iface
.cast(this);