Connect myeclipse to the MySQL database

Source: Internet
Author: User

I am giving my classmates a J2EE course on the struct + hibernate structure. The database used Oracle before. The database is lost and I don't want to install oracle. It's too easy to install it on the book, can't unload disgusting... just change MySQL and change it for him. Some posts on the Internet are too old. The version and the website are all refurbished, but the content is too big to be powerful. I still cannot rely on the network, after all, you have to believe in yourself. thinking is king.

The above are all nonsense. Start:

 

 

Before connecting to the MySQL database using myeclipse, you need to do the following:

Steps:

1. Install JDK, tomcat, and myeclipse (now myeclipse8.5 is fully encapsulated, and eclipse is not needed. Of course, I personally think I should try to build a platform using eclipse)

A few words:

There are many types of eclipse versions. Depending on your own development purposes, you can find the desired development version, eclipse3.5 Galileo version + Joss tools (plug-in) + myeclipse plug-in, which is enough, this kind of hands-on can give you a thorough understanding. Independent of binding, because the visualization has become less, the configuration files are all handwritten, and you can write juint for testing by yourself.

The above nonsense is enough for your development to carry out J2EE heavyweight development for struct + hibernate + spring.

URL: http://www.eclipse.org/downloads/

:

 

 

2. Connect driver required by myeclipse to connect to MySQL (I have anyone who wants to leave a mailbox for me, I will send it to you, and the company will send it to the desired group at noon ),

This also provides the official address: Detailed description, detailed steps

Next:

 

Next:

 

Next:

 

Next, we will see some versions in Europe and Asia. Remember: you can choose either the US version or the US version.

 

The plug-in is ready. What should I prepare next? --> Install mysql. I will not elaborate on this because I think there is only one problem with installing MYSQL: Remember the user name and password !!!

 

Officially entered the topic:

Looking at the picture directly, I think I'm stupid, direct, and will get scolded if I talk nonsense.

1.

 

Note: The result of the two options is the same.

 

2.

 

3.

Click Finish to complete the database driver connection.

4.


Open the connection ---- test whether the database configuration is successful ---- as long as you are not naughty, it will succeed !!!

 

5. Next, add the MySQL DATA connection package:

 

If you do not want to write it, the next time I edit it, I will click Next. Then I will see a name: mysqljars, click addjars on the right, and find your

 

Click Finish ....

Then you can see a Java class in your project. Test it. OK. Of course, you must have a database first. I will paste the code and class code first.

 

Class Name: Whatever it is

Package com. bipt. dB;

Import java. SQL. statement;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. resultset;
Import java. SQL. sqlexception;
Public class dbcon {
Public static connection conn = NULL;
Public static statement stmt = NULL;
Public static resultset rs = NULL;

Public void getcon () throws classnotfoundexception, sqlexception {
Class. forname ("com. MySQL. JDBC. Driver ");
Conn = drivermanager. getconnection ("JDBC: mysql: // localhost/btestdemo? "
+ "User = root & Password = bipt ");
}

Public void closecon (connection conn) throws sqlexception {
If (Conn! = NULL)
Conn. Close ();

}

Public static void main (string [] ARGs ){
Dbcon DBC = new dbcon ();
Try {
DBC. getcon ();
Stmt = conn. createstatement ();
Rs = stmt.exe cutequery ("select * from user ");
While (Rs. Next ()){
System. Out. println (Rs. getint ("userid "));
System. Out. println (Rs. getstring ("username "));
System. Out. println (Rs. getstring ("userpassword "));
// System. Out. println (Rs. getstring ("usermail "));
// System. Out. println (Rs. getdate ("usertime "));
// System. Out. println (Rs. getstring ("userintegral "));
// System. Out. println (Rs. getstring ("usersex "));
System. Out. println ();
}
System. Out. println ("Conn:" + dbcon. Conn );
System. Out. println ("MySQL test succeeded ");
} Catch (classnotfoundexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}

}

 

 

 

 

MySQL script:

Create Table 'user '(
'Userid' int (11) not null auto_increment,
'Username' varchar (30) not null default '',
'Userpassword' varchar (30) default '',

Primary Key ('id ')
) Engine = InnoDB default charset = gb2312;
Go

 

 

When you run this Java class, the console will display the user information in the database. It's too late to go to bed and edit it the next day. It's too messy.

 

Hope to help you!

PS: original post http://blog.csdn.net/democreen/article/details/6024413

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.