aspose file tools*
The moose likes JDBC and the fly likes help in coding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "help in coding" Watch "help in coding" New topic
Author

help in coding

roy ramos
Greenhorn

Joined: Nov 17, 2009
Posts: 26
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





-roy
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
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.


JDBCSupport - An easy to use, light-weight JDBC framework -
roy ramos
Greenhorn

Joined: Nov 17, 2009
Posts: 26
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

Joined: Feb 23, 2009
Posts: 1183


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

Joined: Nov 05, 2007
Posts: 40
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

Joined: Feb 23, 2009
Posts: 1183
Coding boss, please put your code between code tags. Makes things much more enjoyable for everybody ;-)
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
ok sebastain..sorry..
ahha ahhaa
roy ramos
Greenhorn

Joined: Nov 17, 2009
Posts: 26
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

Joined: Nov 05, 2007
Posts: 40
no probs roy...use mysql-connector-java-5.1.7-bin.jar for my sql..
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
he is using MS SQL ... and the driver he is using is okay
bala manian
Ranch Hand

Joined: Nov 05, 2007
Posts: 40
ok it sqljdbc.jar..
roy ramos
Greenhorn

Joined: Nov 17, 2009
Posts: 26
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

Joined: Nov 17, 2009
Posts: 26



Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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 .


Thanks,
Sherif
roy ramos
Greenhorn

Joined: Nov 17, 2009
Posts: 26
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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help in coding