⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbcquery.java

📁 java连接数据库的程序代码 可以从数据库中读取相应的内容
💻 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 + -