i am writing a java problem connecting to mysql database. i don't know why data type decimal or numeric woudn't store any decimal numbers.

my java program would output:

Type was: DECIMAL

when trying to insert number like 23.50.

what data type should i be using? probably not numeric or decimal i guess.

thanks

What's your java code? Certainly a decimal would work with a value of 23.50 (that's what a decimal is) and numeric could work if it had appropriate precision values.

hum,, darkagn i guess you are right. I actually checked my mysql database table. the decimals were inserted correctly. it is just my java program can't read it back out.

here is my code but i guess i should do this in the java forum

import java.sql.*;
import java.sql.Driver;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import javax.swing.*;
import java.io.*;

public class DataHolder
{
	private Connection connection;
	private Statement statement;
	private ResultSet resultSet;
	private Employee employee; 
	
	
	DataHolder(Boolean getAll)
	{
		String url = "jdbc:mysql://127.0.0.1:3306/employees"; 
		String username = "root";
		String password = "root";
		
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection(url, username, password );
		}
		
		catch(ClassNotFoundException cnfex)
		{
			System.err.println("Failed to load JDBC/ODBC driver.");
			cnfex.printStackTrace();
			System.exit(1);
		}
		
		catch(SQLException sqlex)
		{
			System.err.println("Unable to connect");
			sqlex.printStackTrace();
		}
		
		if(getAll =true)
		{
			getAllData();
		}
		
		
		
	}// end constructor

	
	public void getAllData()
	{
		try
		{
			String query = "SELECT * FROM employees";
			statement = connection.createStatement();
			resultSet = statement.executeQuery(query);	
		}
		
		catch(SQLException sqlex)
		{
			sqlex.printStackTrace();
		}
	}// end getAllData
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.