📄 makingtheconnection.java
字号:
import java.sql.*;
public class MakingTheConnection
{
public static void main(String[] args)
{
// Load the driver
try
{
// Load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Define the data source for the driver
String sourceURL = "jdbc:odbc:technical_library";
// Test for driver version
int verMajor;
float verComplete;
float verPreferred;
// Set the minimum preferred version
verPreferred = 1.1f;
// Set the driver
Driver theDriver = DriverManager.getDriver(sourceURL);
// Get the version number to the left of the decimal point, e.g. 1 out of 1.0
verMajor = theDriver.getMajorVersion();
/* Make a float of the complete version number by adding the minor number (to the
right of the decimal point, e.g. 1108 out of 1.1108) on to verMajor */
verComplete = Float.parseFloat(verMajor + "." + theDriver.getMinorVersion());
// Test to see if we have a suitable version of the driver
if(verComplete >= verPreferred)
System.out.println("Version " + verComplete + " found");
//Make the connection...
else
System.out.println("Required version of driver (" +
verPreferred + ") not found");
// Otherwise drop out
// Create a connection through the DriverManager
Connection databaseConnection =
DriverManager.getConnection(sourceURL);
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch(SQLException sqle)
{
System.err.println(sqle);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -