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

📄 connect.java

📁 学生管理系统简单实训,只用于学习之用
💻 JAVA
字号:
package mainface;
import java.sql.*;
public class Connect {//数据库连接部分
	  String[]  strin=null;
      Connection conn;
      int i=0;
      int k=0;
      String string[];
      String str[][]=new String[50][7];;
      public Connection getTable(){//数据库的连接;
    	  try{
    		   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    		   System.out.println("数据库驱动程序加载驱动成功!");
    		   }catch(Exception s){
    		    System.out.println("数据库加载驱动失败!");
    			s.printStackTrace();
    		   }
    	  try{
    		  conn=DriverManager.getConnection("jdbc:odbc:student","","");
    		  System.out.println("数据库连接成功!");
    	  }catch(Exception a){
    		  System.out.println("数据库连接不成功!");
    	  }
    	  return conn;
       }
       public String[] Quiry(String args,String args1){//数据库的查询;
    	  
    	  Connection  conn=getTable();
     	  try{
     		 
     		  strin=null;
     	      PreparedStatement state=conn.prepareStatement("select*from chengjibiao where "+args+" = ?");
     	      state.setString(1,args1);
     	      ResultSet result=state.executeQuery();
              while(result.next()){
              String id=result.getString("ID");
     		  String name=result.getString("name");
     		  String xuehao=result.getString("xuehao");
     		  String birthday=result.getString("birthday");
     		  String math=result.getString("math");
     		  String english=result.getString("english");
     		  String Cyuyan=result.getString ("Cyuyan");
     		  strin=new String[]{id,xuehao,name,birthday,math,english,Cyuyan};                                                          
     		 }
     	      
              
       }catch(Exception t){
    	   t.printStackTrace();
       }
         return strin;
       }
       public String[][]  ScanL(){
    	    k=0;
    	   Connection con=getTable();
    	   try{
    		   PreparedStatement state=con.prepareStatement("select*from chengjibiao ");
    		   ResultSet result=state.executeQuery();
    		 while(result.next()){
    			    k++;
    	           String id=result.getString("ID");
    			   String name=result.getString("name");
    		       String xuehao=result.getString("xuehao");
    	     	   String birthday=result.getString("birthday");
    	     	   String math=result.getString("math");
    	     	   String english=result.getString("english");
    	     	   String Cyuyan=result.getString ("Cyuyan");
    	     	   string=new String[]{id,xuehao,name,birthday,math,english,Cyuyan};  
    	     	   for(int j=0;j<7;j++)
    	     		 str[i][j]=string[j]; 
    	     	   System.out.println(str[i][2]);
    	     	   ++i;
    	          }
    		      for(int j=0;j<i;j++)
    		    	  {for(int a=0;a<7;a++)
    		    		  System.out.print(str[j][a]+" ");
    		              System.out.println();}
    		    }catch(Exception a){
    	    	   a.printStackTrace();
    	       }
    	       return str;
       }
       public int Cont(){
    	   return  k;
       }
       public  boolean InsertQ(String s[]){//数据插入;
    	  Connection con=getTable();
    	  boolean n;
    	  try{
    		  PreparedStatement state=con.prepareStatement("insert into chengjibiao values(?,?,?,?,?,?,?)");
    		  for(int j=0;j<7;j++)
    		  state.setString(j+1,s[j] );
    		  state.executeUpdate();
    		  n=true;
    	  }catch(Exception a){
    		  a.printStackTrace();
    		   n=false;
    	  }
    	  return n;
       }
       public boolean Delete(String a,String b){//数据删除;
         Connection con=getTable();
         boolean n;
         try{
        	   PreparedStatement state=con.prepareStatement("delete  from  chengjibiao  where "+a+ "  =  ?");
        	    state.setString(1,b);
        	  // state.setString(2,b);
        	   System.out.println(a+b);
        	   state.executeUpdate();
        	   n=true;
        	  }catch(Exception e){
        		  n=false;
        	 e.printStackTrace();
         }
        	  return n;
       }
       public boolean upDate(String a[]){
    	   boolean h;
    	   Connection con=getTable();
           try{System.out.println();
          	 PreparedStatement state=con.prepareStatement("update chengjibiao  set  "+a[0]+"  =  " +"'"+a[1]+"'"+"   where  "+a[2]+  "= "+"'"+a[3]+"'" );
          	   state.executeUpdate();
          	   if(a[1]==null||a[3]==null)
          		   h=false;
          	   else
          	   h=true;
          	  }catch(Exception e){
          	 e.printStackTrace();
          	 h= false;
           }
          	  return h;
       }
       public static void main(String args[]){
    	  String b[]={"name","'蔡正武'","ID","'123'"};
    	 new Connect().upDate(b);
       }
     
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -