JSP connect to JDBC in Bean
843859Apr 8 2007 — edited Apr 8 2007This is the program from bean file(MySQL.java)
I have written this program and I want to use JSP to call this bean file.
What's the program? Can anybody show the program to me?
you can provide me if you have some URL which is showing this issue.
Thanks.
package com.jdbc.test;
import java.sql.*;
public class MySQL {
public static void main (String[] args) {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/userlogin";
String username = "";
String password = "";
showEmployeeTable(driver, url, username, password);
}
public static void showEmployeeTable(String driver,
String url,
String username,
String password)
{
try{
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement();
String query = "Select userid from userlogin";
ResultSet resultSet = statement.executeQuery(query);
while(resultSet.next()){
System.out.print(resultSet.getString("userid"));
}
connection.close();
} catch(ClassNotFoundException cnfe) {
System.err.println("Error loading driver: " + cnfe);
} catch(SQLException sqle) {
System.err.println("Error with connection: " + sqle);
}
}
}