当前位置: 技术问答>java相关
关于JDBC, 请哪位大侠帮忙告诉我完整的JDBC的联结方式
来源: 互联网 发布时间:2015-01-04
本文导语: 关于JDBC, 请哪位大侠帮忙告诉我完整的JDBC的联结方式 我现在对于JAVA与DB2的联结不是很清楚,请大侠帮忙!一 点小分,不成敬意!先谢谢了! | import java.sql.*; public class faq { String sDBDriver ...
关于JDBC, 请哪位大侠帮忙告诉我完整的JDBC的联结方式
我现在对于JAVA与DB2的联结不是很清楚,请大侠帮忙!一
点小分,不成敬意!先谢谢了!
我现在对于JAVA与DB2的联结不是很清楚,请大侠帮忙!一
点小分,不成敬意!先谢谢了!
|
import java.sql.*;
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
|
import java.sql.*;
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq"; /*faq是odbc数据源吧?,它应放在那?可以换成其他目录吗?*/
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver); //这里装载的驱动是sun公司自己开发的吗?,他都能连那些数据库?
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
):不好意思,占用别人的地盘...欢迎指点......
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq"; /*faq是odbc数据源吧?,它应放在那?可以换成其他目录吗?*/
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver); //这里装载的驱动是sun公司自己开发的吗?,他都能连那些数据库?
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
):不好意思,占用别人的地盘...欢迎指点......
|
哎呀 一般都有通过JDBC-ODBC连接乔形势连接的方式亚
|
faq是odbc数据源,一般在控制面板里设置,还可以有用户名和密码,详细请参考JDK1.3