Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class SQLUtil {
- public static synchronized String getHtmlRows(ResultSet results) throws SQLException {
- StringBuffer htmlRows = new StringBuffer();
- ResultSetMetaData metaData = results.getMetaData();
- int columnCount = metaData.getColumnCount();
- htmlRows.append("<table>");
- htmlRows.append("<tr>");
- for(int i = 1; i <= columnCount; i++)
- htmlRows.append("<td><b>" + metaData.getColumnName(i) + "</b></td>");
- htmlRows.append("</tr>");
- while(results.next()) {
- htmlRows.append("<tr>");
- for(int i = 1; i <= columnCount; i++)
- htmlRows.append("<td>" + results.getString(1) + "</td>");
- htmlRows.append("</tr>");
- }
- htmlRows.append("</table>");
- return htmlRows.toString();
- }
- public static Connection getConnection() {
- try{
- Class.forName("com.mysql.jdbc.Driver");
- String dbURL = "jdbc:mysql://localhost:3306/murach";
- String username = "root";
- String password = "";
- Connection connection;
- connection = DriverManager.getConnection(dbURL, username, password);
- System.out.println("Connection successful: " + connection.toString());
- return connection;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement