Users who are new to jsp (the preferred choice for SUN enterprise-level applications) often ask how to connect to the database. I write an article here for your reference,
Now let's start our jsp (first choice for SUN Enterprise applications) and database journey!
● Jsp (preferred for SUN Enterprise Applications) connect to MySQL (the best combination with PHP) Database
TestMySQL (the best combination with PHP). jsp (the preferred choice for SUN Enterprise Applications) is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Body>
<% Class. forName ("org. gjt. mm. MySQL (the best combination with PHP). Driver"). newInstance ();
String url = "jdbc: MySQL (the best combination with PHP): // localhost/softforum? User = soft & password = soft1234 & useUnicode = true & characterEncoding = 8859_1"
// TestDB is your database name
Connection conn = DriverManager. getConnection (url );
Statement stmt = conn. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_UPDATABLE );
String SQL = "select * from test ";
ResultSet rs1_stmt.exe cuteQuery (SQL );
While (rs. next () {%>
The content of your first field is: <% = rs. getString (1) %>
Your second field content is: <% = rs. getString (2) %>
<% }%>
<% Out. print ("database operation successful, congratulations"); %>
<% Rs. close ();
Stmt. close ();
Conn. close ();
%>
</Body>
</Html>