wood burning stoves 2.0*
The moose likes JSP and the fly likes SQL Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "SQL Exception" Watch "SQL Exception" New topic
Author

SQL Exception

Ram Kas
Ranch Hand

Joined: Jul 26, 2006
Posts: 83
<html>
<body>
<%@ page import = "java.sql.*" %>
<%
String name = request.getParameter("T1");
String password = request.getParameter("T2");

out.println(name);
out.println(password);

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbcdbc:myDataSource");
Statement st = con.createStatement();


String sql = "insert into reg values("+name+","+password+") ";
System.out.println(sql);
boolean b=st.execute(sql);
}
catch(ClassNotFoundException ce)
{
System.out.println("ClassNotFoundException");
}
catch(SQLException se)
{
System.out.println("SQL Exception"+se.getMessage());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
%>
</body>
</html>
[ September 16, 2006: Message edited by: Bear Bibeault ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30299
    
150

Linking to the previous one


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30299
    
150

Originally posted by Dinakar Kasturi:
String sql = "insert into reg values("+name+","+password+")";

This is the line that is giving you trouble. Name and password are Strings, so they need to be in quotes for the database. Try:
Ram Kas
Ranch Hand

Joined: Jul 26, 2006
Posts: 83
Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Exception