ORA-01465: invalid hex number while insert data from text area - html

i want insert data from jsp page to oracle database. i use textarea tag for write message.it s my contact form
here is my sql code
Create Table message(
id number primary key,
name varchar2(50),
student_id number,
mess varchar2(4000),
reply varchar2(4000));
and this is jsp code
String name = request.getParameter("name");
String mess = request.getParameter("mes");
String sid = (String) session.getAttribute("STID");
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:XE", "system", "12345");
ps = conn.prepareStatement("insert into message values(id_seq.nextval,?,?,?");
ps.setString(1, name);
ps.setString(2, sid);
ps.setString(3, mess);
when i click button i get ORA-01465: invalid hex number error. how can i resolve it?

Related

error on inserting data into mysql using python

my aim was to insert name, userID and password of user so i used this code.
os.system('cls')
nme = input("enter your name: ")
usid = input("enter your userID: ")
pasd = int(input("please enter a pin in digits, characters are not supported: "))
entry = """insert into users (name, ID, pin) values('nme', 'usid', 'pasd')"""
curs.execute(entry)
but in the line5, instead of value getting inserted from variables, the whole variable is getting recognised as data input. please help!!

Python errors occurring trying to insert data into a MySQL database table

I need to create an sql login/ sign up system for my program, however I keep hitting this error no matter what I do to change it. I need to have a randomly generated UTID, the users first and surname, along with a password that is verified, then the UserID is generated by taking the first three letters of the first name and the whole surname. I cant figure out how to overcome this.
I have tried to give the values inside the sql statement when inserting some literal datatypes, like writing "
c.execute('insert INTO tbl_Teachers (str(UTID), str(FName), str(SName), str(userPass), str(userID))VALUES(?,?,?,?,?);', var_insert) " but nothing seems to work.
def signup():
name = []
surname = []
print("Please enter the following details.")
user_type = str(input("Are you a teacher or a student: "))
if user_type == ("teacher") or ("Teacher"):
var_FName = str(input("First Name: "))
var_LName = str(input("Last Name: "))
var_password1 = str(input("Choose a password: "))
var_password2 = str(input("Please confirm password: "))
UTID = str(random.randint(0,100000))
print ("Your UserID is "+UTID+"")
name.append(var_FName)
surname.append(var_LName)
userID = []
for x in range (0, 3):
userID.append(var_FName[x])
for x in range (0,len(var_LName)):
userID.append(var_LName[x])
print (userID)
if var_password1 != var_password2:
print("Please try again.")
else:
var_insert = []
var_insert.append(UTID)
var_insert.append(var_FName)
var_insert.append(var_LName)
var_insert.append(str(var_password1))
var_insert.append(userID)
conn = sqlite3.connect('Program.db')
c = conn.cursor()
c.execute('insert INTO tbl_Teachers (UTID, FName, SName, userPass, userID)VALUES(?,?,?,?,?);', var_insert)
conn.commit()
InterfaceError: Error binding parameter 4 - probably unsupported type.
userID is supposed to be a string, but you're creating a list. Use string concatenation, not the append method.
userID = var_FName[0:3] + var_LName

java.sql.SQLException: Column count doesn't match value count at row 1 jdbc [duplicate]

This question already has answers here:
java.sql.SQLException: Column count doesn't match value count at row 1
(3 answers)
Closed 6 years ago.
Connection conn = null;
PreparedStatement pst = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/chatdata", "admin", "int*M=9167757203");
pst = conn.prepareStatement("insert into user values (?, ?)");
} catch (Exception e) {
}
String password;
String userName;
try {
BufferedReader kin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Username :: ");
userName = kin.readLine();
System.out.println("Enter Password :: ");
password = kin.readLine();
pst.setString(1, userName);
pst.setString(2, password);
pst.execute();
} catch (Exception e) {
System.out.println(e);
}
This code is showing me the error:
"java.sql.SQLException: Column count doesn't match value count at row
1"
While my table has three column entries uid which is AUTO_INCREMENT and username and password the two strings that I have to pass so please if anybody can find the answer please help.
This is what the MySQL manual says about using an insert without column list:
If you do not specify a list of column names for INSERT ... VALUES or
INSERT ... SELECT, values for every column in the table must be
provided by the VALUES list or the SELECT statement.
So, even if uid has the autoincrement flag, you still need to specify in the insert statement for which columns you present values. As a solution, you can simply modify your insert statement:
insert into user (username, password) values (?, ?)
(I supposed that username and password are the names of the columns.)
You can read more about using autoincrement here
netbeans evaluates the field in different way in mysql cmd if you would type this syntax say
insert into user ('username', 'password') values ('xyz', 'abc');
it would work perfectly fine but in netbeans the tables and field names are indicated not in single quotes but in `` this type of quotes so this would perfectly fine in netbeans
insert into user (username, password) values ('xyz', 'abc');
where string like xyz and abc are expressed in single quotes...

Select count return 0 mysql JDBC

I'm trying to store messages, so i create 2 tables in mysql with HeidiSql, the first one is msg and the second one is users. I wrote a store procedure to get the number of messages that have as sender the first parameter, as recipient the second parameter and viceversa, i stored this value in id variable. I need the variable to count the messages between 2 people. When i run the application from java, i always get id=0. I can't understand the mistake.
...
sql="call getIdMsg(?,?,?)";
sql2="call addRecord(?,?,?,?)";
try (Connection conn= DriverManager.getConnection(db_url,username,password);
CallableStatement statement = conn.prepareCall(sql);
CallableStatement statement2 = conn.prepareCall(sql2)){
statement.setInt(1,sender);
System.out.println(sender);
statement.setInt(2,recipient);
System.out.println(recipient);
statement.registerOutParameter(3, Types.INTEGER);
statement.execute();
id=statement.getInt(3);
System.out.println("ID is: "+id);
statement2.setInt(1,sender);
statement2.setInt(2,recipient);
statement2.setInt(3,id);
statement2.setString(4,msg);
statement2.execute();
System.out.println("The record is been added");
}
catch (SQLException sqle){sqle.printStackTrace();}
...
This is my sql code:
BEGIN
set #id = ((select count(*) from msg WHERE sender = #thisrecipient and recipient = #thissender)+(SELECT COUNT(*) FROM msg WHERE sender = #thissender and recipient = #thisrecipient));
END
These are my parameters:
thissender INT IN
thisrecipient INT IN
id INT OUT
Could you help me please?

how to check if a data exist on a table using hibernate

im using hibernate with my jsp page and mySQL ,how can i do that select * from student wher userName = *** with HQL
and how i chek if that username exist in 'Student' table ?
in my sql i use that
ResultSet resultat = statement.executeQuery();
if (resultat.next()) { ....}
i try this
Session hibernateSession = MyDB.HibernateUtil.currentSession();
hibernateSession.find("select xxx from Etudinat where p.Nom=xxxx");
its give me a list but
i have a login form send me a username and password
i want to chek if that username exist in the table Student to set the user on a session
what is the safty way to do that
I could not paste code into the comment. Try the following HQL:
from Etudinat where Nom = 'xxxx'
Even better, pass the username as a parameter.
Per OP request, code snippet based on the comments:
Query q = hibernateSession.createQuery("from Etudinat where Nom = :username");
q.setParameter("username", xxxx);
Etudinat e = q.uniqueResult();