📄 jdbcquery.java
字号:
import java.sql.*;
class JDBCQuery{
public static void main(String args[]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:db1");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT*FROM 表1");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
};
stmt.executeUpdate("Insert into 表1 VALUES('Leilei','Hebei',21)");
System.out.println(" 添加数据后的信息为");
rs=stmt.executeQuery("SELECT*FROM 表1");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
};
stmt.executeUpdate("Delete from 表1 where name='Jenny'");
System.out.println(" 删除后的信息为:");
rs=stmt.executeQuery("Select*From 表1");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
rs.close();
stmt.close();
conn.close();
}}
catch(SQLException se){
System.out.print("SQL Exception:");
//Loop throught the SQL Exceptions
while(se!=null){
System.out.println("State :"+se.getSQLState());
System.out.println("Message:"+se.getMessage());
System.out.println("Error:"+se.getErrorCode());
se=se.getNextException(); } }
catch(Exception e){
System.out.println(e); }} }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -