java動態建立數據庫(sql server)

public static void main(String[] args) {
		// TODO Auto-generated method stub
		 String url = "jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=base_name;user=sa;password= pas";//sa身份鏈接    
		    
	    
	        Connection con = null;    
	        Statement stmt = null;    
	        //ResultSet rs = null;    
	        boolean rs ;
	        try {    
	            Class.forName("net.sourceforge.jtds.jdbc.Driver");    
	            con = DriverManager.getConnection(url);  
	            stmt = con.createStatement();    
	            System.out.println("end.");    
	            String sql1="drop table aa";
	            rs = stmt.execute( sql1);  
	            System.out.println("我刪除了一張表");
	            String SQL = "create table aa(" +
	            		"	id	int 	null," +
	            			"currdate	date null,)";    
	         
	            rs = stmt.execute(SQL); 
	            System.out.println("我建立了一張表");
	           // rs = stmt.executeQuery(SQL);    
	    
	          /*  while (rs.next()) {    
	                System.out.println(rs.getString(4) + " " + rs.getString(6));    
	            }   */ 
	        }    
	    
	        catch (Exception e) {    
	            e.printStackTrace();    
	        }    
	    
	        finally {    
	        	/*if(rs!=null){
	        		rs.colse();
	        	}*/
	            if (stmt != null)    
	                try {    
	                    stmt.close();    
	                } catch (Exception e) {    
	                }    
	            if (con != null)    
	                try {    
	                    con.close();    
	                } catch (Exception e) {    
	                }    
	        }    
	}
相關文章
相關標籤/搜索