Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Exception

 
Ram Kas
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic