除了建立 jdbc 连接或使用内部使用 jdbc 的框架之外,还有其他方法可以连接到数据库吗?
问问题
8098 次
2 回答
6
Sure, it's possible. But not likely.
You'd have to understand the protocol that the database vendor expected completely.
You'd have to write your own client to converse with the vendor's listener on the server side.
It can be done, but I doubt that you or I would be up to it.
The big question is: why?
于 2013-04-05T10:53:47.677 回答
0
您可以使用 JDBC ODBC 桥...虽然不推荐..
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
public class Main {
public static void main(String[] args) throws Exception {
Connection conn = getConnection();
Statement st = conn.createStatement();
// st.executeUpdate("drop table survey;");
st.executeUpdate("create table survey (id int,name varchar(30));");
st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM survey");
ResultSetMetaData rsMetaData = rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
System.out.println("resultSet MetaData column Count=" + numberOfColumns);
st.close();
conn.close();
}
private static Connection getConnection() throws Exception {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:northwind";
String username = "";
String password = "";
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}
}
于 2013-04-05T10:46:19.080 回答