📄 makingastatement.java
字号:
import java.sql.*;
public class MakingAStatement
{
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";
// Create a connection through the DriverManager
Connection databaseConnection =
DriverManager.getConnection(sourceURL);
Statement statement = databaseConnection.createStatement();
ResultSet authorNames = statement.executeQuery(
"SELECT lastname, firstname FROM authors");
// Output the resultset data
while(authorNames.next())
System.out.println(authorNames.getString("lastname")+" "+
authorNames.getString("firstname"));
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch(SQLException sqle)
{
System.err.println(sqle);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -