当前位置: 技术问答>java相关
如何用 JDBC 连接 Interbase 数据库?
来源: 互联网 发布时间:2015-03-29
本文导语: 请给一个例子,说明如何使用 JDBC 连接 Interbase 数据库?谢谢。 | public int getCount(String sqlstr) { int count = -1; Connection con = null; Statement stmt = null; ...
请给一个例子,说明如何使用 JDBC 连接 Interbase 数据库?谢谢。
|
public int getCount(String sqlstr)
{
int count = -1;
Connection con = null;
Statement stmt = null;
try {
con = myBroker.getConnection();
stmt = con.createStatement();
ResultSet results = stmt.executeQuery(sqlstr);
ResultSetMetaData rsmd = results.getMetaData();
results.next();
count = Integer.parseInt(results.getString(1));
results.close();
}
catch (Exception e)
{
;
}
finally {
try{
if(stmt != null){
stmt.close();
}
}catch(SQLException e1){};
}
// The connection is returned to the Broker
myBroker.freeConnection(con);
return count;
}
{
int count = -1;
Connection con = null;
Statement stmt = null;
try {
con = myBroker.getConnection();
stmt = con.createStatement();
ResultSet results = stmt.executeQuery(sqlstr);
ResultSetMetaData rsmd = results.getMetaData();
results.next();
count = Integer.parseInt(results.getString(1));
results.close();
}
catch (Exception e)
{
;
}
finally {
try{
if(stmt != null){
stmt.close();
}
}catch(SQLException e1){};
}
// The connection is returned to the Broker
myBroker.freeConnection(con);
return count;
}
|
下面的例子是用于MYSQL,我想SQL Server和它大体一样.
你先下载MYSQL和它的JDBC驱动程序,按下面的配置走一遍.(肯定没问题)
成功后再做SQL Server,就会轻车熟路了!
俺也没SQL Server的JdBC驱动程序,所以也没法试!
1) Go to JDBC Explorer and select "View | Options" from the menu. Click on
the "Drivers" tab and then Click on the "Add" button.
Key in the MySQL driver name (I use the one from Mark Mathews):
org.gjt.mm.mysql.Driver
and press OK.
You can enter a sample URL if you like e.g.
mysql://localhost/databasename
2) Go back to JBuilder.
Click on the "Tools | Enterprise Setup" menu option.
Click on the "Database Drivers" tab and the click on the "Add" button.
On the "Select One or More Libraries" dialog click on the "New.." button
Enter the MySQL driver name in the "Name" field i.e.
org.gjt.mm.mysql.Driver
Then click on the "Add" button for Library paths and search/select the
MySQL driver jar file and click "OK" button:
mm.mysql.jdbc-1.2b
Then go back through the panels click on "OK".
I think you should then find that the driver is available for you to use.
3) When you setup a new connection module the MySQL jdbc driver should now
be available and if you set up a "sample URL" in JDBC explorer you should
just have to overtype the database/password details to get it working
语句用
Class.forName(DriveName);
Connection conn = DriverManager.getConnection(url,username,password);
你先下载MYSQL和它的JDBC驱动程序,按下面的配置走一遍.(肯定没问题)
成功后再做SQL Server,就会轻车熟路了!
俺也没SQL Server的JdBC驱动程序,所以也没法试!
1) Go to JDBC Explorer and select "View | Options" from the menu. Click on
the "Drivers" tab and then Click on the "Add" button.
Key in the MySQL driver name (I use the one from Mark Mathews):
org.gjt.mm.mysql.Driver
and press OK.
You can enter a sample URL if you like e.g.
mysql://localhost/databasename
2) Go back to JBuilder.
Click on the "Tools | Enterprise Setup" menu option.
Click on the "Database Drivers" tab and the click on the "Add" button.
On the "Select One or More Libraries" dialog click on the "New.." button
Enter the MySQL driver name in the "Name" field i.e.
org.gjt.mm.mysql.Driver
Then click on the "Add" button for Library paths and search/select the
MySQL driver jar file and click "OK" button:
mm.mysql.jdbc-1.2b
Then go back through the panels click on "OK".
I think you should then find that the driver is available for you to use.
3) When you setup a new connection module the MySQL jdbc driver should now
be available and if you set up a "sample URL" in JDBC explorer you should
just have to overtype the database/password details to get it working
语句用
Class.forName(DriveName);
Connection conn = DriverManager.getConnection(url,username,password);
|
For example:
dbdriver=interbase.interclient.Driver
dbserver=jdbc:interbase://192.168.1.240/c:/initDb/InterBase/vdbib.gdb
Then u can use JDBC API to connect to Interbase
Any problems, contact me.
Y do you use InterBase? Y not MySQL ...?
dbdriver=interbase.interclient.Driver
dbserver=jdbc:interbase://192.168.1.240/c:/initDb/InterBase/vdbib.gdb
Then u can use JDBC API to connect to Interbase
Any problems, contact me.
Y do you use InterBase? Y not MySQL ...?