Step 1
Run the 32-bit odbc driver using
WinKey+R, then copy-paste the below command
C:\Windows\SysWOW64\odbcad32.exe
Step 2
Make a dsn named “SQLDB” or whatever name you want to.
Step 3
Create a new project in eclipse.
Step 4
Change the jre to the java installed inside
C:\Program Files (x86)\java
Use this as “JRE System Library”
Step 5
Use the below code to connect to connect to SQL Server (It's a SQL_Connection class)
DONE!!!!import java.sql.*; public class SQL_Connection { public static Connection GetConnection() { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect=DriverManager.getConnection("jdbc:odbc:SQLDB"); return connect; } catch(Exception ex) { ex.printStackTrace(); return null; } } public static int ExecuteQueryString(String querystring) { try{ Statement st= GetConnection().createStatement(); return st.executeUpdate(querystring); } catch(Exception ex) { ex.printStackTrace(); } return -1; } public static ResultSet getResultSet(String querystring) { try{ Statement st= GetConnection().createStatement(); ResultSet rs= st.executeQuery(querystring); return rs; } catch(Exception ex) { //ex.printStackTrace(); return null; } } public static void Close_Connection(Connection conn) { try {conn.close();} catch(Exception ex) {} } }
Kommentar veröffentlichen
Spam for back-link will be remove