|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我也不知道,我原来理解的,NET就是C++编程,只是与JAVA相对,呵呵。以为.ET就是高级C++编程。如今很多多少程序,都是与数据库相干的,因而在做安装的时分,部署数据库看似是一件很庞大的事变。实在就我团体而言,部署数据库是很复杂,大抵的思绪以下:
1.用自己的DBMS来发生数据库创立的SQL剧本;
2.接上去就是写程序来实行SQL剧本,从而到达创立数据库的目标。
以下用一个举例来讲明,数据库服务器用的是SQLServer。
起首要在数据库天生好的SQL剧本最前头,到场以下语句:
usemaster
GO
ifexists(select*fromsysdatabaseswherename=mytest)
dropdatabasemytest
GO
createdatabasemytest
GO
usemytest
GO
注:个中“mytest”是要创立的数据库名。
而程序的代码以下:
//---------------------------CreateDB-------------------------------------
//-------------------------------------------------------------------------
//---File:frmCreateDB.cs
//---Description:ThemainformfiletocreatedatabaseusingspecificSQLfile
//---Author:Knight
//---Date:Mar.18,2006
//-------------------------------------------------------------------------
//-------------------------{CreateDB}-----------------------------------
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.IO;
namespaceCreateDB
{
///<summary>
///SummarydescriptionforfrmCreateDB.
///</summary>
publicclassfrmCreateDB:System.Windows.Forms.Form
{
privateSystem.Windows.Forms.Labellabel1;
privateSystem.Windows.Forms.TextBoxtxtServerName;
privateSystem.Windows.Forms.Labellabel2;
privateSystem.Windows.Forms.Labellabel3;
privateSystem.Windows.Forms.TextBoxtxtUserName;
privateSystem.Windows.Forms.TextBoxtxtPassword;
privateSystem.Windows.Forms.ButtonbtnCreateDB;
///<summary>
///Requireddesignervariable.
///</summary>
privateSystem.ComponentModel.Containercomponents=null;
publicfrmCreateDB()
{
//
//RequiredforWindowsFormDesignersupport
//
InitializeComponent();
//
//TODO:AddanyconstructorcodeafterInitializeComponentcall
//
}
///<summary>
///Cleanupanyresourcesbeingused.
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#regionWindowsFormDesignergeneratedcode
///<summary>
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///</summary>
privatevoidInitializeComponent()
{
this.label1=newSystem.Windows.Forms.Label();
this.txtServerName=newSystem.Windows.Forms.TextBox();
this.txtUserName=newSystem.Windows.Forms.TextBox();
this.label2=newSystem.Windows.Forms.Label();
this.txtPassword=newSystem.Windows.Forms.TextBox();
this.label3=newSystem.Windows.Forms.Label();
this.btnCreateDB=newSystem.Windows.Forms.Button();
this.SuspendLayout();
//
//label1
//
this.label1.AutoSize=true;
this.label1.Location=newSystem.Drawing.Point(32,32);
this.label1.Name="label1";
this.label1.Size=newSystem.Drawing.Size(74,16);
this.label1.TabIndex=0;
this.label1.Text="ServerName:";
//
//txtServerName
//
this.txtServerName.Location=newSystem.Drawing.Point(120,32);
this.txtServerName.Name="txtServerName";
this.txtServerName.Size=newSystem.Drawing.Size(152,20);
this.txtServerName.TabIndex=1;
this.txtServerName.Text="";
//
//txtUserName
//
this.txtUserName.Location=newSystem.Drawing.Point(120,64);
this.txtUserName.Name="txtUserName";
this.txtUserName.Size=newSystem.Drawing.Size(152,20);
this.txtUserName.TabIndex=3;
this.txtUserName.Text="";
//
//label2
//
this.label2.AutoSize=true;
this.label2.Location=newSystem.Drawing.Point(40,64);
this.label2.Name="label2";
this.label2.Size=newSystem.Drawing.Size(64,16);
this.label2.TabIndex=2;
this.label2.Text="UserName:";
//
//txtPassword
//
this.txtPassword.Location=newSystem.Drawing.Point(120,96);
this.txtPassword.Name="txtPassword";
this.txtPassword.PasswordChar=*;
this.txtPassword.Size=newSystem.Drawing.Size(152,20);
this.txtPassword.TabIndex=5;
this.txtPassword.Text="";
//
//label3
//
this.label3.AutoSize=true;
this.label3.Location=newSystem.Drawing.Point(48,96);
this.label3.Name="label3";
this.label3.Size=newSystem.Drawing.Size(57,16);
this.label3.TabIndex=4;
this.label3.Text="Password:";
//
//btnCreateDB
//
this.btnCreateDB.Location=newSystem.Drawing.Point(168,136);
this.btnCreateDB.Name="btnCreateDB";
this.btnCreateDB.Size=newSystem.Drawing.Size(104,23);
this.btnCreateDB.TabIndex=6;
this.btnCreateDB.Text="&CreateDB";
this.btnCreateDB.Click+=newSystem.EventHandler(this.btnCreateDB_Click);
//
//frmCreateDB
//
this.AutoScaleBaseSize=newSystem.Drawing.Size(5,13);
this.ClientSize=newSystem.Drawing.Size(306,175);
this.Controls.Add(this.btnCreateDB);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtUserName);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtServerName);
this.Controls.Add(this.label1);
this.FormBorderStyle=System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox=false;
this.Name="frmCreateDB";
this.StartPosition=System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text="CreateDB";
this.ResumeLayout(false);
}
#endregion
///<summary>
///Themainentrypointfortheapplication.
///</summary>
[STAThread]
staticvoidMain()
{
Application.Run(newfrmCreateDB());
}
privatevoidbtnCreateDB_Click(objectsender,System.EventArgse)
{
SqlConnectionsqlConn=newSqlConnection();
try
{
sqlComm.ExecuteNonQuery();
returntrue;
}
catch(SqlExceptionsqlErr)
{
MessageBox.Show(sqlErr.Message);
}
catch
{
}
sqlComm.Dispose();
}
returntrue;
}
}
}
要注重的是在SQL剧本中的“
”,在SQLCommand中是没法辨认,因而要交换为空格;其次“GO”在SQLCommand中也是没法辨认,但为了使每条语句都实行,因而我在这里,用“;”来交换。
注:程序的地位和SQL剧本文件的地位为统一目次下,假如以为不便利的话,能够在我的基本上再延长。
归根到底,Java跨平台可以,但是要重新编写代码,否则还分什么J2EE/J2SE/J2ME呢! |
|