一样的。faq 里看一下就知道了。
解决方案 »
- 这句java代码是什么意思?
- 初学者问题求教,请各位大神指教
- 一个JAVA初学者关于JAVA数据类型的一个疑问
- java 访问远程数据库问题
- java 将文件上传到服务器指定目录下 !!!!!!!!!!!!!!!!!!
- jfreecahrt柱子问题
- 百分求助, 如何实现Java中的 goto 操作, 如何将Java程序翻译成 Applet?
- 高分求助java gui中有关scroll的问题。
- 咨询linux和java高手
- 听说java.net.ftp不是很好用,有第3方的class吗?
- 有没有方法让鼠标只能在一个JFrame中移动?
- java中能否获取自己所在的进程ID(进程表中的)以及如何判断自己的运行方式
This example uses an Oracle JDBC driver to connect to an Oracle database instance located at 128.0.0.0:1521 with an sid called mydatabase.
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
// Create a connection to the database
String serverName = "127.0.0.1";
String portNumber = "1521";
String sid = "mydatabase";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "username";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}Connecting to a MySQL Database
This example connects to a MySQL database using the MM JDBC driver for MySQL. You need to have an account in MySQL database to run this example. To create an account, you can connect to MySQL database on your platform as root, and run the following command:
mysql> GRANT ALL PRIVILEGES ON *.* TO username@localhost
IDENTIFIED BY 'password' WITH GRANT OPTION;
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
// Create a connection to the database
String serverName = "localhost";
String mydatabase = "mydatabase";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "username";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}Connecting to a SQLServer Database
This example connects to a SQLServer database using the NetDirect JDBC driver. For information about this driver, see e232 Getting JDBC Drivers for a Database.
Connection connection = null;
try {
String driverName = "com.jnetdirect.jsql.JSQLDriver"; // NetDirect JDBC driver
String serverName = "127.0.0.1";
String portNumber = "1433";
String mydatabase = serverName + ":" + portNumber;
String url = "jdbc:JSQLConnect://" + mydatabase; // a JDBC url
String username = "username";
String password = "password";
// Load the JDBC driver
Class.forName(driverName);
// Create a connection to the database
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}
配合 Keepers(中文昵称) 的代码使用呢?或者,不在JBuilder里,怎么配置JDBC?
好像不用JDBC-ODBC桥就可以?
Keepers(中文昵称) 的代码里,连接SQL Server用的是什么?
谢谢着急中
如果在jb中,那么加到项目中引用就可以了
我上边的帖子中有三种连接mysql\oracle\sqlserver,你一定没有仔细看。
我把sql放在下边。
Connecting to a SQLServer Database
This example connects to a SQLServer database using the NetDirect JDBC driver. For information about this driver, see e232 Getting JDBC Drivers for a Database.
Connection connection = null;
try {
String driverName = "com.jnetdirect.jsql.JSQLDriver"; // NetDirect JDBC driver
String serverName = "127.0.0.1";
String portNumber = "1433";
String mydatabase = serverName + ":" + portNumber;
String url = "jdbc:JSQLConnect://" + mydatabase; // a JDBC url
String username = "username";
String password = "password";
// Load the JDBC driver
Class.forName(driverName);
// Create a connection to the database
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}