Skip to content

@greghelton /OldSchoolJDBC.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Java: code to verify Java can connect to 1995 SQL Server Database
package old.school;
import java.sql.*;
/**
* run as follows:
* 1. javac OldSchoolJDBC.java
* 2. java OldSchoolJDBC
*/
public class OldSchoolJDBC {
Connection conn;
public OldSchoolJDBC() {}
public void connect() throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:windows-datasource-name",
"USERID", "PASSWORD");
}
public void query() throws Exception {
Statement stmt = conn.createStatement();
String qry = "SELECT * FROM sc_admin.abendcodesa4";
ResultSet rs = stmt.executeQuery(qry);
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
public static void main(String[] args) {
try {
OldSchoolJDBC p = new OldSchoolJDBC();
p.connect();
p.query();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.