Is there any other way to connect to the database other than making a jdbc connection or using frameworks which internally use jdbc.
Asked
Active
Viewed 9,393 times
2
-
4Why would you ever want to do that? – David Apr 05 '13 at 10:39
-
why not JDBC connection? what's your difficulty behind ? – Raptor Apr 05 '13 at 10:39
-
1http://stackoverflow.com/questions/2397016/java-jdbc-alternatives – David Apr 05 '13 at 10:39
-
It depends on the database. Most DB servers typically communicate directly via sockets – MadProgrammer Apr 05 '13 at 10:40
-
You could (theoretically...) create a JNI binding for your database's native C/C++ API (e.g. OCI in case of Oracle RDBMS) – Andreas Fester Apr 05 '13 at 10:43
-
1All of the JDBC alternatives in the link above are built on JDBC, so you're still using it. – duffymo Apr 05 '13 at 10:55
-
One reason why you may want to, and why I came here: Because you are access user data that is stored in their database, and you don't know what DBMS they have. You don't want to include several DBMS in your application if you don't have to. – gagarwa Nov 30 '17 at 17:55
2 Answers
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?

duffymo
- 305,152
- 44
- 369
- 561
0
You can use JDBC ODBC Bridge ... not recommended though..
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);
}
}

Waqas Memon
- 1,247
- 9
- 22
-
1
-
-
2Yes you are, you just don't know it. You're using the bridge driver that Oracle/Sun wrote. They're a third party. And it's still JDBC. See the first four letters in the driver and connection URL? – duffymo Apr 05 '13 at 10:54
-
http://stackoverflow.com/questions/3771594/unix-socket-connection-to-mysql-with-java-to-avoid-jdbcs-tcp-ip-overhead – Waqas Memon Apr 05 '13 at 10:56
-
1Right, but that's not what your code says. And they are agreeing with my recommendation: write your own client from scratch, understanding the protocol completely. You're making my point. – duffymo Apr 05 '13 at 10:58
-
then you know the answer... why would someone like to do that anyway... do you really need any such thing? – Waqas Memon Apr 05 '13 at 10:59
-
yes indeed i did make ur point. i just pasted the right answer ... so, one needs reinvent the wheel rather then use it if this question is ever to be answered. – Waqas Memon Nov 07 '17 at 00:38
-