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

help in coding

 
roy ramos
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody help me on this i'm new in programming and i'm having problem in this coding

here is the code



the tomcat server logs this

Exception is ;java.sql.SQLException: Unexpected parameter marker at position 46.

this is line 46

if(userName.equals(request.getParameter("user")) &&

can anybody please help to point the error on this coding




 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem must be somewhere else ... it's an SQLException meaning that some database related action went wrong.

Could you send the whole exception text and the related code snippet?

Also, you should check out JDBCSupport. It eases the interaction with databases ;-) Check the link below.
 
roy ramos
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sebastian,

that's the only error i found in my tomcat server logs, i'm only newbie in programming so i'm not sure if my database code is ok, when i try my code it always say i'm not authentic but the user name and password that i use is correct because i only have 1 entry on my database, i'm not using any IDE in coding only notepad
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Print the result of that to the console using System.out.println to see if he got the correct record from the database.

Also, don't use new String("") ;-)
 
bala manian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is your coding boss...

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class jdbc extends HttpServlet{


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{

PrintWriter out = response.getWriter();
// String connectionURL = "Jdbc:Oracle:thin:@put oracle installed ip no:1521:test","test","test";
Connection connection=null;
ResultSet rs;
String userName=new String("");
String passwrd=new String("");
response.setContentType("text/html");
try {

Class.forName("oracle.jdbc.driver.OracleDriver");

connection =DriverManager.getConnection("Jdbc:Oracle:thin:@put oracle installed ip no:1521:test","test","test");
String sql = "select * from PASSWORD_MASTER ";
PreparedStatement s = connection.prepareStatement(sql);

rs = s.getResultSet();
while (rs.next ()){
userName=rs.getString("USER_ID");
passwrd=rs.getString("PASSWORD");
}
rs.close ();
s.close ();
}catch(Exception e){
System.out.println("Exception is ;"+e);
}
if(userName.equals(request.getParameter("user")) &&
passwrd.equals(request.getParameter("pass"))){
out.println("User Authenticated");
}
else{
out.println("You are not an authentic person");
}
}
}


above i used is oracle thin driver(type 4)ie ojdbc14.jar..enjoy roy..



 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coding boss, please put your code between code tags. Makes things much more enjoyable for everybody ;-)
 
bala manian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok sebastain..sorry..
ahha ahhaa
 
roy ramos
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bala,

the code works on you? you change only the driver is it? but i'm using MS SQL not oracle
 
bala manian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no probs roy...use mysql-connector-java-5.1.7-bin.jar for my sql..
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
he is using MS SQL ... and the driver he is using is okay
 
bala manian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok it sqljdbc.jar..
 
roy ramos
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sebastian,

the print result give me nothing

Sebastian Janisch wrote:

Print the result of that to the console using System.out.println to see if he got the correct record from the database.

Also, don't use new String("") ;-)
 
roy ramos
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
roy ramos wrote:



Roy , it's better for you to use IDE specially when you are coding j2ee , and to send the full exception stack .
 
roy ramos
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sherif,

thanks for advised, i will try to use netbeans

Sherif Shehab wrote:
roy ramos wrote:



Roy , it's better for you to use IDE specially when you are coding j2ee , and to send the full exception stack .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic