📄 jdbctest.txt
字号:
import java.sql.*;
public class JdbcTest
{
public static void main(String[] args)
{
String url="jdbc:odbc:Mydatasource";
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
con=DriverManager.getConnection(url);// 实际上,我们可以将这个程序写成更一般的形式,即不在程序中固定用哪一种驱动程序,
//不固定uRL、用户名和口令,而是把它们作为参数,在程序执行曲时候由用户输入see Page96
sm=con.createStatement();
//sm.executeUpdate("INSERT INTO Test " + "VALUES (001,'mary')");//It's strange that there must be a blank after the table name!
sm.executeUpdate("insert into 操作员 " + "values('005','xiangxiang',' ','005',' ',' ')");
rs=sm.executeQuery("SELECT* FROM 操作员 WHERE 状态 LIKE '在职'");
while(rs.next())
{
String opID=rs.getString(1);
String opName=rs.getString(2);
System.out.println("操作员ID:"+opID);
System.out.println("操作员姓名:"+opName);
}
}catch(SQLException ex)
{
ex.printStackTrace();
}
finally
{
try
{
rs.close();
sm.close();
con.close();
}catch(SQLException ex)
{
ex.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -