0
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
InputStream inputStream = null; // input stream of the upload file

// obtains the upload file part in this multipart request
Part filePart = request.getPart("audio");
if (filePart != null) {
// prints out some information for debugging
System.out.println(filePart.getName());
System.out.println(filePart.getSize());
System.out.println(filePart.getContentType());

// obtains input stream of the upload file
inputStream = filePart.getInputStream();
}

String message = null; // message will be sent back to client

try {
// connects to the database
DriverManager.registerDriver(new com.mysql.jdbc.Driver());

// Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, "root", "root");

// constructs SQL statement
String sql = "INSERT INTO user_music_library (id,audio) values (?, ?)";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setString(1,"1");

if (inputStream != null) {
// fetches input stream of the upload file for the blob column
statement.setBlob(2, inputStream);
}

// sends the statement to the database server
int row = statement.executeUpdate();
if (row > 0) {
message = "File uploaded and saved into database";
}
}
// catch(Exception e)
// {
// pw.println(e); 
// }
catch(SQLException ex) {
message = "ERROR: " + ex.getMessage();
ex.printStackTrace();
}
// sets the message in request scope
request.setAttribute("Message", message);

// forwards to the message page
getServletContext().getRequestDispatcher("/Message.jsp").forward(request, response);
}

this is my code to upload audio bt cannot upload only upto amount of kbs. i used BLOB datatype in mysql it does not have anylongblob.
so now can anyone help me upload audio,display them on jsp and play them after selecting them

Edited by peter_budo: Moved to Java web development

3
Contributors
4
Replies
21
Views
2 Years
Discussion Span
Last Post by jwenting
1

"display audio on jsp" ...
the type of application you work with isn't relevant, whether it's a standalone using swing or javafx or a webapp using gwt or jsp/jsf, the persistence is not impacted by this.

"but cannot upload only upto amount of kbs" what exactly do you mean by that?
and what do you mean by "display audio on jsp"?

0

the audio files that are stored, i want them to be retrived and play and them when user clicks on them.

0

sorry, you're dead wrong. Blobs are the way to store binary data in a relational database.
AND audio files are far from unstructured.

the audio files that are stored, i want them to be retrived and play and them when user clicks on them.

Take a look at JSF (you want it instead of JSP anyway) and especially Primefaces which has audioplayer components.
Other JSF libraries may have them as well, but Primefaces is very good and pretty much accepted across the industry.

Edited by jwenting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.