Connecting to the database using jts and some SQL statements

Source: Internet
Author: User
Export package: jtds-1.2.2.jarpublicclassDBUtil {*** get database connection * @ return * publicstaticConnectiongetConnection () {Connectionconnnull; try {1. load the driver Class. forName (net. sourceforge. jtds. jdbc. driver); connection string jdbc: jtd

Export package: jtds-1.2.2.jar public class DBUtil {/*** get database connection * @ return */public static ConnectiongetConnection () {Connectionconn = null; try {// 1. load the driver Class. forName (net. sourceforge. jtds. jdbc. driver); // connection string jdbc: jtd

Package: jtds-1.2.2.jar


PublicclassDBUtil {

/**

* Obtain the database connection

*@ Return

*/

PublicstaticConnectiongetConnection (){

Connectionconn =Null;

Try{

// 1. Load the driver

Class.ForName("Net. sourceforge. jtds. jdbc. Driver ");

// Connection string "jdbc: jtds: sqlserver: // IP: Port/Database Name ";

FinalString url = "jdbc: jtds: sqlserver: // 127.0.0.1: 1433/SuperDogMall ";

// Log on to the database account

FinalString user = "sa ";

// Login Database Password

FinalString password = "123456 ";

Conn = DriverManager.GetConnection(Url, user, password );

}Catch(ClassNotFoundException e ){

E. printStackTrace ();

}Catch(SQLException e ){

E. printStackTrace ();

}

ReturnConn;

}

PublicstaticvoidMain (String [] args ){

System.Out. Println (DBUtil.GetConnection());

}

}


SQL statements for table creation and content insertion:

Use SuperDogMall

-- Create Table userinfo

Create tableuserinfo

(UserIdvarchar (20) primarykey,

UserPassword varchar (20) notnull,

UserName varchar (20 ),

UserEmail varchar (40 ),

UserBirth datetime,

UserAddress varchar (40 ),

UserMoney int

)

Select * fromuserinfo

Insert into userinfovalues ('zhizunbao', '123', 'zhizunbao @ supermall.com ', '2017-10-10', 'jiuzhaigou, Sichuan Province, 123)

Insert into userinfovalues ('ershixiong ', '123456', '2's elder brother', 'ershixiong @ supermall.com ', '2017-11-14', 'weihai City, Shandong Province ', 123)

Insert into userinfovalues ('zixiaxianzi', '000000', 'zixia xianzi', 'zixiaxianzi @ supermall.com ', '2017-11-14', 'sichuan silk cave ', 123)

Insert into userinfovalues ('niumowang ', '123456', 'niumagow', 'niumowang @ supermall.com', '2017-11-14 ', 'niu toushan, Sichuan Province', 123)

Insert into userinfovalues ('tieshan', '1234568', 'tieshan @ supermall.com ', '2017-11-14', 'huoyan mountain of Xinjiang province, 123)

Create tableproduct

(

ProId varchar (20) primarykey,

ProName varchar (20 ),

ProType varchar (20 ),

ProPrice float check (proPrice> = 0 ),

ProStore int check (proStore> = 0 ),

ProSales int check (proSales> = 0 ),

ProPicture varchar (60 ),

ProDesc varchar (200)

)

Select * fromproduct

Insert into productvalues ('P _ 001', 'dog ignores Steamed Stuffed Bun ', 'food', '5', '123', '123', '', 'delicious ')

Insert into productvalues ('P _ 002', 'qingfeng Steamed Stuffed Bun ', 'food', '2', '123456', '', 'delicious ')

Insert into product values ('P _ 003 ', 'dianyuan Steamed Stuffed Bun', 'food', '1', '123', '123', '', 'delicious ')



Some driver and url statements:

Oracle
Driver = "oracle. jdbc. driver. OracleDriver"
Url = "jdbc: oracle: thin: @ localhost: 1521: Database Name"
Sqlserver
Driver = "com. microsoft. jdbc. sqlserver. SQLServerDriver"
Url = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = database name"
Mysql
Driver = "com. mysql. jdbc. Driver"
Url = "jdbc: mysql: // localhost/Database Name? [Followed parameters]"
Db2
Driver = "com. ibm. db2.jdbc. app. DB2Driver"
Url = "jdbc: db2: // localhost: 5000/database name"
Sybase
Driver = "com. sybase. jdbc. SybDriver"
Url = "jdbc: sybase: Tds: localhost: 5007/database name"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.