Unable To Create A Connection In JSP Program To MSSQL Database
Oct 7, 2014
i have a problem in connecting my jsp program in MSsql 2005 i want to create a connection in my jsp program to MSsql database but theres an error of my work here is my code
Code:
PHP Code:
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>
<%@ page import="java.sql.*;" %>
<%@ page import="java.util.Enumeration;" %>
<html>
<head><title>Sample MS connection</title></head>
[Code]...
View Replies
ADVERTISEMENT
Jan 15, 2015
I have a shop and I use visual studio.net to create an Inventory application to manage my shop. So I am familiar with vb.net codes.
Now, I'm trying to built another Inventory application for my shop using java, 'coz now I'm using Linux Ubuntu for my OS desktop and there's no visual studio.net in linux.
So in vb.net, there's a module that I use for database connection that I can call from any form that I needed.
I searched google for the equivalent module for java and there is none. But, there's an example that use a new java class.
Here's the code in MySQLConnect.java :
Java Code:
public class MySQLConnect {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/dbInventory";
static final String USER = "root";
static final String PASS = "root";
public static Connection ConnectDb() {
[Code] ....
View Replies
View Related
Dec 6, 2014
I am trying to create a program for class the uses two dimensional arrays. I am stuck on the second step that states Use two parallel arrays. One is a two-dimensional array -- a row of this array will hold six values in this order: [0] number of hours worked, [1] hourly pay rate, [2] gross pay, [3] net pay, [4] federal withholding, and [5] state withholding.
This is what I have so far:
Java Code:
double [][] data = new double [30][6];
String [] names = new String [30];
String str = null;
String detail = null;
int n = input(data, names, inputFile); mh_sh_highlight_all('java');
(there's more but i don't believe it pertains to this question)
My question is how would I create this array. Or, is that right above? I've searched online and in my book and I just don't understand.
View Replies
View Related
Aug 21, 2014
I have failed with all possibilities that I know to make this program success. Getting error as :
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Program goes like this.
import java.sql.*;
public class ExcelConnection {
public static void main (String[] args){
try {
Connection conn = getConnection("TEST.xls");
Statement stmt = conn.createStatement();
[Code] ....
View Replies
View Related
Apr 10, 2014
I am trying to check SFTP connection to remote server using enchanter jar. Mine is not a multi-threaded application. PFB sample code...
.....
SSH ssh = new DefaultSS();
ssh.setTimeOut(10000);
ssh.connect("myserver","myusername","mypassword");
ssh.sendLine("cd /u");
ssh.sendLine("sftp -B batch.file utodldse@claoesdsdd.com");
ssh.getLine();
.....
note - the batch.file contains only 1 statement. Please find below.
---
bye
---
But the above program is getting is stuck at times when the server is not responding. It goes into infinite hung state.
Is there some alternative ways to set timeout ?
View Replies
View Related
Jan 15, 2015
I was wondering if I could take the following code and somehow put the connection to database in it's own class without the "public static void main(String[] args)" method. That way I could call it anytime i want to open a connection to the database.
Java Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Sample {
public static void main(String[] args) throws ClassNotFoundException
[Code] ....
View Replies
View Related
Oct 27, 2014
I'm using oracle 10g Database and Java 'jdk1.7.0_45' version.I have to a create program to insert data into a table.
View Replies
View Related
Sep 16, 2014
I'm using JSF framework. I can let Netbeans to create the persistence unit and hardcodes connection parameters into the persistence.xml file or i can use resource tag in context.xml file or using another file like property file or class for holding connection parameters like username and password; what is the most secure way or expert way to use connection properties in my app or there is no difference?
View Replies
View Related
Mar 15, 2015
I am trying to make a simple login using netbeans, derby database included in netbeans and tomcat server. I made everything nice and separated: I have a model package with a class called DbConnector that has the following method:
public Connection connect() {
try {
return DriverManager.getConnection(url, user, pass);
} catch (SQLException ex) {
return null;
}
}
Then i have another class, an userDAODB that has a password check method:
public boolean checkPassword(String user, String password) {
try (Connection con = new DbConnector().connect(); Statement stmt = con.createStatement()) {
//checks the password in the database
In the main method of this class i tested everything, it works very nice, logs me in, other methods work too, no problem what so ever.But then i go to my servlet:
public class LoginTest extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String username = request.getParameter("username");
String pass = request.getParameter("pass");
UserDAODB userDAO = new UserDAODB();
boolean authe = userDAO.checkPassword(username, pass);
[code]....
So when i start the webpage and i try to click on the login button I get a NullPointerException com.model. UserDAODB. check Password (User DAODB. java:14) - so line 2 here
I have been googling a bit, i placed the derby.jar and the derbyclient.jar in the lib directory of tomcat, i tried to modify the context.xml of my application, but then it wouldn't even start anymore.
View Replies
View Related
May 21, 2014
I am trying to make connection with oracle database but when i run java file it's raise an error
"classnotfoundexception oracle.jdbc.driver.oracledriver"
DriverManager.getConnection(
"jdbc:oracle:thin:@erp:1521:ORCL", "apps",
"apps");
View Replies
View Related
Jul 10, 2015
I have small Java code, which execute every day and checks for data in database using Cronj Schedular and everything works fine, but recently I have observed that, it is failing due to
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@160.110.xx.xxx:1521/test
At the same time, when I run my test code to check Database connectivity that works fine without above exception. I'm unable to figure it out. Although, there was just slight code change, but that was nowhere related to Database or Database connection.
dbconf.java
public class dbconf {
private Connection connect;
private String connstr;
public Connection getConnection() throws SQLException {
connstr = "jdbc:oracle:thin:@160.110.xx.xxx:1521/test";
[Code] ....
Application Log file
Wed Jul 01 09:25:17 IST 2015:------- Initializing -------------------
Wed Jul 01 09:25:17 IST 2015:------- Scheduling Jobs ----------------
Wed Jul 01 09:25:17 IST 2015:------- Job Started Running ----------------
Thu Jul 02 06:00:00 IST 2015 : Job Executed..!! Bschedularv2.2
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@160.xxx.67.xxx:1521/test
Sat Jul 04 06:00:00 IST 2015 : Job Executed..!! Bschedularv2.2
Sun Jul 05 06:00:00 IST 2015 : Job Executed..!! Bschedularv2.2
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@160.xxx.67.xxx:1521/test
So, you can see, It failed on 3rd of July and 5th July as well. But, in between it ran fine.
View Replies
View Related
May 25, 2012
I am trying to use a custom listener to initialize database connection pool (C3P0) on start up and then destroy on context shut down. The reason for that is that I whenever context is shutdown I have a memory leak because initialized connection pool is not being destroyed.
I have a static class called C3P0Utils that deals with connection pool. In my listener in contextInitialized method I have tried at first to init the pool like this :
+public void contextInitialized(ServletContextEvent sce) {+
+try {+
C3P0Utils.newInstance().init();
+} catch (PropertyVetoException ex) {+
Logger.getLogger(DatabaseInit.class.getName()).log(Level.SEVERE, null, ex);
+}+
+}+
I know that object is created. I checked it using jconsole. However it is not accessible with in the application. My second attempt was to regester the pool and then add it to the context and then when I need it read from there.
+public void contextInitialized(ServletContextEvent sce) {+
+try {+
ServletContext ctx=sce.getServletContext();
C3P0Utils.newInstance().init();
ctx.setAttribute("myDataSource", C3P0Utils.newInstance().getDataSource());
+} catch (PropertyVetoException ex) {+
Logger.getLogger(DatabaseInit.class.getName()).log(Level.SEVERE, null, ex);
+}+
+}+
However when I try to red from the context I get nothing. I try to read like this.
+(ComboPooledDataSource)ctx.getAttribute("myDataSource")+
When I print names of all of the attributes in the context I get these attributes.
Context Name
org.apache.tomcat.InstanceManager
org.apache.catalina.jsp_classpath
javax.servlet.context.tempdir
org.apache.catalina.resources
+org.apache.tomcat.JarScanner
+org.apache.jasper.compiler.TldLocationsCache
+org.springframework.web.context.WebApplicationContext.ROOT
Why I can not use anything initialized in the listener.
View Replies
View Related
Jun 19, 2014
We have a J2EE business web application that runs in WebLogic. We noticed in application log files errors messages that seems like "No resource available in db pool", it means all the connection objects (to Oracle database) are used. Then the application is unstable and unseable.
I think the maximum number of connections configured in Weblogic pool has been reached due to an increase of users and activity. But when the workload decreases the application is still out of service. It seems connections objects are not relased to the pool. What can be the explanation for this issue ? Normally it is managed by the container (EJB3 for the business tier).
Once the limit of the pool is reached it is necessary to restart the server to solve this kind of error ?
View Replies
View Related
Dec 31, 2014
I have a vps set up to running a MySQL database already by zpanel but when I try to connect to the database with Java I am unable to connect and receive the message:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."
I have MySQL Connector(dev.mysql.com/downloads/connector/j) already added to my build and tried it with both the url and the ip. This is my connection code:
package net;
import java.sql.*;
import javax.swing.JOptionPane;
public class LoginDatabaseConnection {
Connection conn = null;
[Code] ....
The code is from youtube but when I connect to localhost it works fine however when I try to connect to the VPS the above error happens.
View Replies
View Related
May 13, 2014
date.jsp
<form action="insertDateServlet" method="post">
Name: <input type="text" name="name">
<label for="from">Available Date</label>
<input type="text" id="from" name="from">
<label for="to">Final date</label>
<input type="text" id="to" name="upto"><br>
<input type="submit" name="submit">
</form>
blank values are going to database
insertDateServlet.java
String name= request.getParameter("name");
String Available_from = request.getParameter("from");
String Available_Upto = request.getParameter("upto");
Sql query="insert into db values(?,?,?)";
[Code]...
View Replies
View Related
Feb 7, 2014
i have a problem, im trying to get some values from a jtable (tabla) and insert them in a mysql database, so i scan the table for some values to know which of the rows i must insert ("s" or "n").
I'm able to insert few rows, but when the last row with "s" or "n" is inserted it launch me a NullPointerException and I dont know why.
public void insertar(JTable tabla, int rowt, int colt) throws ParseException{
String documento=null, cve_clie=null, fechaE=null, fechaR=null, check=null;
char d=' ',dd=' ',m=' ',mm=' ',y1=' ',y2=' ',y3=' ',y4=' ';
String chck = null;
try{
conexion = connMysql.mysql();
String squery="insert into consefact3 values (?,?,?,?,?)";
PreparedStatement pst = conexion.prepareStatement(squery);
[Code]...
View Replies
View Related
Mar 20, 2015
I am trying to display rows from my database from servlet by passing it to a JSP, but nothing is displayed. I checked the syntax and even the source of the page shows that it gets the data but the rows are not displayed!
My servlet (serv.jsp)
package Pack1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
[Code]....
My JSP (SP.jsp)
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search Page</title>
</head>
<body>
<h1>TITLE</h1>
[Code]....
My servlet file is in the Pack1 package under Source Packages and jsp file is under Web Pages.
View Replies
View Related
May 27, 2014
[public class Login
{
private String username;
private String password;
private String login_time;
private String logout_time;
private String status;
private String late;
[Code]...
but i am getting an error as but i am getting an error as
java.lang.NoSuchMethodException: com.tribro.chandu.Login.post();
View Replies
View Related
Jan 31, 2013
I'm creating a web applicaion. for that i want to create a registration page. and this registration details have to be stored in the database.
I'm getting the below error while trying to send the data ...
The requested resource (/cmd/InsertRegtodb) is not available.
Here cmd is project name and InsertRegtodb is servlet name.
Actually the servlet is present is the mentioned address. but it is not connecting to it
There is one more servlet in the same folder and which is accessible from another jsp. But this servlet is not accessible even though i have used same code as it is used for the servlet which worked for me previously...
View Replies
View Related
Sep 1, 2014
I have created a JSP page, on click of a particular button, the control moves to the servlet "TestServlet".
This is the code under TestServlet:
import java.io.IOException;
import java.io.PrintWriter;
import java.security.Principal;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
[Code]...
Now, I have got a comment saying I should get the database connection from connection pool. And one more issue is that I have used the function System.getProperty("user.name") to get the username which i have logged in. But this code will be run on Unix which will not support this function. Any function where I can get the windows username. There is a function getUserPrincipal(), but this function returns a NULL. How to resolve this.
View Replies
View Related
Jan 11, 2015
I configured a connection pool in tomcat 7. For every database activity I get a connection from the pool. Do I have to close the connection like other regular connection after the database operation is done? If I close the connection will it have any effect on the connection pool?
View Replies
View Related
Jul 6, 2014
I am trying to create an MP3 player with a totally customized look and feel to it. I know how to do this with .net, but I must be missing something in Java.
I want to be able to NOT have to present the user with the default mediaPlayer.getControlPanelComponent() in order to control the media player. I want to be able to code it to when the user clicks on my "Play" button, I can tell the player to play the song, and so on.
so far I get this far:
try {
player = Manager.createPlayer(playit.toURI().toURL());
player.start();
//Component c = player.getControlPanelComponent();
} catch (IOException | NoPlayerException ex) {
Logger.getLogger(TagTester.class.getName()).log(Level.SEVERE, null, ex);
}
...but cannot seem to find out where to go from there.
If familiar with AxWindowMediaPlayer in .NET, I am looking for something similar to:
AxWindowMediaPlayer.Ctlcontrols.play()
when my "Play" button is clicked.
View Replies
View Related
Mar 9, 2015
I am trying to create a serversocket that send a binary in parts ie send 1024 bytes then wait for acknowledgement from the client before sending the next 1024. I am able to do it in udp but the client is tcp. This is my code so far
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class TestFtp {
[Code]....
I have not been able to send then receive acknowledgement before sending the next 1024 bytes.
View Replies
View Related
Apr 25, 2014
I am completing a USACO online problem and am trying to create a print writer to write to my file(ride.out). I did this:
PrintWriter out = new PrintWriter(new BufferedReader(new FileWriter("ride.out")));
However, a load of undefined constructor errors come up for PrintWriter(BufferedWriter) and BufferedWriter(FileWriter). I have imported java.io.* so I don't know what the issue is. This has worked before.
edit: bufferedreader? i give up(not literally)
View Replies
View Related
Jun 15, 2014
I am trying to create a method that calculates the standard deviation of array. What I want to be able to do is something like this
package standardDevaitionAndMean;
public class StandardDeviationTest {
public static void main (String[] args)
{
int [] array = {12,12,12,12,12,12,12};
standardDev = array.StandardDevation();
System.out.print(standardDev);
}
}
With something like this
package standardDevaitionAndMean;
public class StandardDeviation
{double mean1;
double standDev;
public double Mean(double ... array)
{
for(int i=0; i<array.length;i++)
[Code]...
So basically I want to be able to make an array in a class and be able to calculate its standard deviation with my method in my other class. I know the code I wrote is terrible but I just wanted to show what I am trying to do. I am kind of shaky on how arrays operate
View Replies
View Related
Jan 30, 2015
We are asked to create a JDialog showing our database. I am able to show the database but i can't seem to position the heading panel, table and back button. My back button is also not showing up. Here is part of my code...
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.sql.*;
import javax.swing.*;
[Code] ....
View Replies
View Related