In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
[key] Class.forName ("com.mysql.jdbc.Driver"); / / Database connection statement declaration
Conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/bbs", "root", "root"); / / Local mysql database JDBC connection statement (project name bbs login name root password root)
Conn = DriverManager.getConnection ("jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_xiaoweibbs", "0ww4ox1l0n", "4ik4i5jkwwmxij0lyjl3hmlx3kkyyi1ii10iih33")
/ / Sina Cloud mysql database JDBC connection statement (the cloud database address and port are fixed "w.rdc.sae.sina.com.cn:3307" web application name is preceded by app_, and then find the web application setting database login name similar to 0ww4ox1l0n and database login password like 4ik4i5jkwwmxij0lyjl3hmlx3kkyyi1ii10iih33)
[1] here is the encapsulation code of my own bbs database:
Remember to change the package com.bjsxt.bbs; / / package name
Import com.mysql.jdbc.Statement
Import java.sql.*
Public class DB {
Public static Connection getConn () {
Connection conn = null
Try {
Class.forName ("com.mysql.jdbc.Driver")
/ / conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/bbs", "root", "root")
Conn = DriverManager.getConnection ("jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_xiaoweibbs", "0ww4ox1l0n", "4ik4i5jkwwmxij0lyjl3hmlx3kkyyi1ii10iih33")
} catch (ClassNotFoundException e) {
E.printStackTrace ()
} catch (SQLException e) {
E.printStackTrace ()
E.printStackTrace ()
}
Return conn
}
Public static Statement createStmt (Connection conn) {
Statement stmt = null
Try {
Stmt = (Statement) conn.createStatement ()
} catch (SQLException e) {
E.printStackTrace ()
}
Return stmt
}
Public static ResultSet ExceruQuery (Statement stmt,String sql) {
ResultSet rs = null
Try {
Rs = stmt.executeQuery (sql)
} catch (SQLException e) {
E.printStackTrace ()
}
Return rs
}
Public static int executeUpdate (Connection conn,String sql) {
Int ret = 0
Statement stmt = null
Try {
Stmt = (Statement) conn.createStatement ()
Ret = stmt.executeUpdate (sql)
} catch (SQLException e) {
E.printStackTrace ()
} finally {
Close (stmt)
}
Return ret
}
Public static void close (Connection conn) {
If (conn! = null) {
Try {
Conn.close ()
} catch (SQLException e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
}
Conn = null
}
Public static void close (Statement stmt) {
If (stmt! = null) {
Try {
Stmt.close ()
} catch (SQLException e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
}
Stmt = null
}
Public static void close (ResultSet rs) {
If (rs! = null) {
Try {
Rs.close ()
} catch (SQLException e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
}
Rs = null
}
Public static PreparedStatement PreparedStmt (Connection conn,String sql) {
PreparedStatement pstmt = null
Try {
Pstmt = conn.prepareStatement (sql)
} catch (SQLException e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
Return pstmt
}
Public static PreparedStatement PreparedStmt (Connection conn,String sql,int autoGeneratedKeys) {
PreparedStatement pstmt = null
Try {
Pstmt = conn.prepareStatement (sql,autoGeneratedKeys)
} catch (SQLException e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
Return pstmt
}
Public static void close (PreparedStatement pstmt) {
If (pstmt! = null) {
Try {
Pstmt.close ()
} catch (SQLException e) {
/ / TODO Auto-generated catch block
E.printStackTrace ()
}
}
Pstmt = null
}
}
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.