Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 14th, 2003, 07:41 AM
joe_h joe_h is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 4 joe_h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy collecting form info and inputting to postgres database

I have made a form in html and am trying to submit 6 values from this form into a database...but I can't work out the code to put in the jsp....I'm new at this stuff so sorry if the coding is poor. Is there a way to send the info straight from clicking "submit" or do I have to somehow return the information back to the page first?

This is what I have so far:

<!-- Set the scripting language to java and import the java.sql package -->
<%& page language="java" import="java.io.*" import="java.sql.*" %>
<%

Connection con = null;

// The driver class name.
String drvName = "org.postgresql.Driver";

// Load the database driver.
try {
Driver drv = (Driver)Class.forName(drvName).newInstance();
} catch (Exception e) {
System.out.println ( "Driver load failed: " + e.getMessage() );
System.exit ( 0 );
}

// Use the DriverManager to open a connection to the database
try {
con = DriverManager.getConnection ( "jdbcostgresql://penguin/xxx", "xxx", "password" );
} catch ( SQLException e ) {
System.out.println ( "getConnection failed: " + e.getMessage() );
System.exit ( 0 );
}

//create the statement and insert data into the Posts table
try {
Statement statement = con.createStatement();
statement.executeUpdate("INSERT INTO Users" + "VALUES('email','username','nativeLang','fluentLang','wantedLang','password')");
if ( rs != null ) {
while ( rs.next() ) {
}
}

// remember to close the ResultSet
rs.close();
} catch ( SQLException e ) {
System.out.println ( "create/execute statement failed: " + e.getMessage() );
System.exit ( 0 );
}

//close the connection.
try{
con.close();
System.out.println("Connection closed.");
} catch (Exception e) {
System.out.println ( "close connection failed: " + e );
}

%>

Reply With Quote
  #2  
Old March 19th, 2003, 11:38 AM
HowardHyde HowardHyde is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 HowardHyde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I do this kind of work with servlets. Here are some missing parts that you might want to consider:

Somewhere in the method that outputs your HTML FORM:

out.println ( "<INPUT TYPE=\"TEXT\" NAME=\"email\" VALUE=\"" + email + "\" SIZE=\"30\">" );

... other fields...

out.println ( "<INPUT TYPE=\"SUBMIT\" NAME=\"frmSubmitEdit\" VALUE=\"Save Changes\">" );


Somewhere in the doPost() method:

if ( request.getParameter ( "frmSubmitEdit" ) != null )
{
frmSubmitEdit ( out, request );
}

...

protected void frmSubmitEdit ( PrintWriter out, HttpServletRequest request )
{
String email = request.getParameter ( "email" );
String username = request.getParameter ( "username" );
String nativeLang = request.getParameter ( "nativeLang" );
String wantedLang = request.getParameter ( "wantedLang" );
String password = request.getParameter ( "password" );
...
String sql = "insert into users (email, username, nativeLang, wantedLang,password) values ( '"
+ email + "', '" + username + "', '" + nativeLang + "', '" + wantedLang + "', '" + password + "'";
statement.executeUpdate (sql);


Hope this helps.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > collecting form info and inputting to postgres database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT