Create a database name Database, username, and account user and pass, then establish a data source in the Control Panel, for clear, data source names for Database, username, and account as described above, then write code as follows, simply test The program and database connection.
Import java.sql. *;
Public class test {public static void main (string ") {string URL =" JDBC: ODBC: Database "; try {class.forname (" sun.jdbc.odbc.jdbcodbcdriver); system.out.println (" "); connection conn = drivermanager.getConnection (URL," User "," pass "); system.out.println (" Success Connect to Database ");} catch (Exception E) {E.PrintStackTrace ();} }
Note that when you build a data source, choose the SQL Server verification using the user to enter the login ID and password.