In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
In order to do the graduation project, I studied Java, and then I had to connect to the database. In order to connect to the database, I did a simple project, address book (now only added functions), and successfully connected to the database.
First of all, take a look at my WEB home page:
It's relatively simple, then fill in the contact page.
The code of my database connection is thrown out first, after all, this is the focus of my address book study.
Package s2.jsp.zhangxiao.daoxiao import java.sql.PreparedStatement;import java.sql.Connection;import java.sql.ResultSet;import java.sql.DriverManager;import java.sql.SQLException;public class AddressBase {/ / define the user name of the database private final String DBNAME = "root"; / / define the password of the database private final String DBPASS = "0" / / define the driver information of the database private final String DRIVER = "com.mysql.jdbc.Driver"; / / define the address to access the database private final String URL = "jdbc:mysql://localhost:3306/addressdb"; public Connection getConnection () {Connection con=null; try {Class.forName (DRIVER); con=DriverManager.getConnection (URL, DBNAME, DBPASS) } catch (ClassNotFoundException e) {System.out.println ("drive exception"); e.printStackTrace ();} catch (SQLException e) {System.out.println ("database exception"); e.printStackTrace ();} return con } public void closeAll (Connection con,PreparedStatement past,ResultSet rs) {try {rs.close ();} catch (SQLException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} try {past.close () } catch (SQLException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} try {con.close ();} catch (SQLException e) {/ / TODO Auto-generated catch block e.printStackTrace () }} public int update (String sql,String [] getValues) {int iTuno; Connection con=null; PreparedStatement past=null; ResultSet rs=null; con=getConnection (); try {past=con.prepareStatement (sql); if (getValuesinvalid null) {for (int j = 0; j < getValues.length) I=past.executeUpdate +) {past.setString (jacks 1, getValues [j]);}} i=past.executeUpdate ();} catch (SQLException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} return I;}}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.